Mastery Points
0
Strings Fundamental in dsa
Context & Logic
A string is a sequence of characters. In JavaScript, strings are primitive values and are immutable, meaning they cannot be changed once created. Common operations include concatenation, slicing, and searching.
Example
const str = "Hello";
console.log(str[0]); // 'H'
// str[0] = 'h'; // Error in strict mode, strings are immutable
const lower = str.toLowerCase(); // Returns new stringStep-by-Step Logic
1
Use indexing to access characters at O(1).
2
Use built-in methods like slice(), substr(), and split() for manipulations.
3
Strings are often treated similarly to arrays in traversal-based problems.
4
Remember that JavaScript strings use UTF-16 encoding.
Complexity Metrics
Time Efficiency
Access: O(1), Manipulation: O(n)
Memory Footprint
O(n) to store the string