Home
DSA Course
Strings
Basics of Strings
Basics of Strings
Understand String representation (ASCII) and basic operations like Reversal.
Ready to reverse string.
H
0e
1l
2l
3o
4Intuition
Strings are sequences of characters. In many languages, they are immutable (cannot be changed in place). Reversing a string typically involves swapping characters from both ends moving towards the center.
Concept
- ASCII: Each character is stored as a number (e.g., 'A' = 65, 'a' = 97).
- Immutability: In Java/Python, strings are immutable. Modifying them creates a new string. In C++, they are mutable.
- Reversal: Use two pointers (start and end) and swap until they meet.
How it Works
Reversal Algorithm:
- Initialize
L = 0,R = n - 1. - While
L < R: - Swap
str[L]andstr[R]. L++,R--.
Step-by-Step Breakdown
Watch the visualization:
- See the ASCII values for each character.
- Watch the characters swap positions during reversal.
When to Use
- Basic text processing.
- Checking for palindromes.
When NOT to Use
- N/A (Fundamental concept).
How to Identify
"Reverse string", "ASCII value", "Character manipulation".
Frequently Asked Questions
What is Basics of Strings?
Understand String representation (ASCII) and basic operations like Reversal.
What is the time complexity of Basics of Strings?
The time complexity is: Best case varies, Average case O(N), Worst case varies. Space complexity is varies.
