Browse Curriculum

Basics of Strings

Understand String representation (ASCII) and basic operations like Reversal.

Ready to reverse string.
H
0
72
e
1
101
l
2
108
l
3
108
o
4
111

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:

  1. Initialize L = 0, R = n - 1.
  2. While L < R:
  3. Swap str[L] and str[R].
  4. 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.