String Data Structure
A String is a sequence of characters used to represent text. In computer science, strings are typically implemented as arrays of characters. Depending on the programming language, strings can be either mutable (changeable) or immutable (unchangeable).
Time Complexity
- Access (by Index)O(1)
- Search (Linear)O(n)
- ConcatenationO(n + m)
- Insert/Delete (middle)O(n)
Immutability Explained
- Java / Python: Strings are immutable. Any modification (like appending a character) actually creates a completely new string in memory, which can be costly (O(n)).
- C++ (std::string): Strings are mutable. You can modify characters in place, similar to an array, often resulting in better performance for heavy manipulation.