String: Data Structure & realted Programs
A string is a collection of characters, encompassing letters, numbers, spaces, and symbols. In
programming languages like Java, Python, or C++, strings are often treated as a distinct data type with
specialized functionalities for manipulation.
In DSA, several key operations and concepts revolve around strings:
Searching: This operation involves locating specific patterns or substrings within a given
string. For instance, in the string "hello world", searching for the substring "world" would return the
index position where it begins.
Sorting: While primarily applied to arrays, strings can also be sorted based on various criteria
such as lexicographic order or length. For instance, sorting the strings "apple", "banana", and "cherry"
would result in "apple", "banana", and "cherry" respectively.
Substrings: Substrings are contiguous sequences of characters within a string. For instance, in
the string "programming", the substring "gram" starts at index 3 and ends at index 6.
String Arithmetic Operations: These operations encompass tasks like concatenation, splitting, and
formatting. For instance, concatenating the strings "hello" and "world" results in "hello world".
Introduction
String Programs
- Reverse a string using a stack
- Count the occurrence of chars in a given string
- Find duplicate chars in a String
- First non-repeating character in String
- Check if two strings are anagram of each other
- Reverse a string
- Check if a string is a valid palindrome