Home
DSA Visualizer
Strings
Basics of Strings
Basics of Strings
A string is a sequence of characters stored as ASCII codes, with basic operations such as reversal.
5 CHARS · 2 SWAPS
SWAP
L
0
1
2
3
R
4
Start with one pointer at each end. Only 2 swaps are needed — each one puts two characters in their final place.
Next
Swap 'H' at 0 with 'o' at 4. Both are now where they belong.
String
Intuition
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".
Applying for software engineering roles? Free, no sign-up:
