What is a String in Data Structure?
What is a String in Data Structure?
A String म्हणजेच characters चा एक क्रम (sequence) असतो. Programming मध्ये ही एक अत्यंत महत्वाची linear data structure आहे जी विविध applications मध्ये वापरली जाते.
Why are Strings Special?
- Small Alphabet Set: Normal arrays मध्ये elements large असू शकतात, पण strings मध्ये typically कमी characters असतात. उदा. English lowercase मध्ये फक्त 26 characters.
- Immutability: काही languages (Java, Python, JavaScript, C#) मध्ये strings immutable असतात. म्हणजे once बनली की ती change होत नाही.
- Optimizations Possible: String problems मध्ये character set लहान असल्यामुळे searching, counting, hashing fast होतं.
Basics of Strings
Introduction to Strings
String म्हणजे एका किंवा अधिक characters चा group, जो double quotes ” ” मध्ये define होतो. उदा. “Technorbit”, “DSA”, “Java”
String Implementations in Various Languages:
- C: Null terminated character array (char str[] = “Hello”;)
- C++: std::string class with powerful operations
- Java: String is immutable class
- Python: Immutable and flexible (str class)
- C#:String class
- JavaScript: Strings are primitive and immutable
- PHP: String is a data type, similar to JS
Basic String Operations:
Operation | Description (English-Marathi) |
Length | String ची length शोधणे (len(str)) |
Equality | दोन strings same आहेत का ते check करणे |
Search | एखादा character string मध्ये आहे का ते शोधणे |
Insert | दिलेल्या position ला character insert करणे |
Delete | एखादा character remove करणे |
Replace | Character replace करणे |
Concatenate | दोन strings जोडणे (concatenation) |
Reverse | string उलटी करणे |
Substrings | सर्व substrings generate करणे |
Easy Level String Problems:
- Check for Binary: फक्त 0 आणि 1 आहेत का string मध्ये?
- Camel Case Conversion: camelCase मध्ये convert करा
- Check for Palindrome: string पलटल्यावर same आहे का?
- Check for Substring: दुसऱ्या string मध्ये आहे का?
- Anagram Check: दोन strings मध्ये तेच characters आहेत का?
- Duplicates: एकाच character ची किती वेळा repeat झाली आहे?
- Left Rotate: String ला एका ठिकाणी rotate करा
- IP Address Validation: IP valid आहे का?
- URLify: Spaces replace करा with %20
- Sort Characters: characters sort करा alphabetical order मध्ये
Medium Level String Challenges:
- First Non-Repeating Character – पहिलं unique character शोधा
- atoi Implementation – String to Integer convert करा
- Add Binary Strings – दोन binary strings add करा
- Roman to Integer – Roman numeral to decimal
- Permutations of String – सर्व permutations generate करा
- Longest Palindromic Substring – सर्वात मोठं palindrome substring शोधा
- Count Anagram Substrings – किती anagram substrings आहेत?
- Word Break Problem – दिलेला string word list मधून divide होतो का?
Hard Level String Challenges:
- Lexicographic Rank of a String – दिलेल्या string चा alphabetical order मध्ये rank
- Multiply Large Numbers as Strings – large numbers store करताना overflow टाळण्यासाठी string वापरून multiplication
- Alien Dictionary – alien language मध्ये order शोधणे
- Palindrome Substring Queries – दिलेल्या substring palindrome आहे का?
- Word Wrap Problem – Space optimize करत word wrap करा
- Minimum Bracket Reversals – expression balance करण्यासाठी किती brackets reverse करावेत?
- Decode Encoded String – 3[a2[bc]] सारखी string decode करा
Advance Concepts and Techniques:
- Prefix Sum in Strings – Fast substring queries साठी
- KMP Algorithm – Pattern Searching
- Z-Algorithm – Efficient substring search
- Rabin-Karp – Rolling Hashing technique
- Trie for Dictionary Matching – Auto-complete systems
- Sliding Window Technique – Substring problems optimize करणे
- HashMaps and Frequency Counters – Occurrence based queries
Practical Applications:
- Text Processing Systems
- Spell Checkers and Grammar Tools
- Compilers आणि Parsers
- Search Engines
- DNA Pattern Matching
- Chat & Messaging Systems
Tips
- Interview मध्ये palindrome, anagram आणि substring problems frequently विचारले जातात
- Real-time systems मध्ये string immutability thread safety साठी useful असते
- Competitive coding साठी KMP, Z-Algorithm, and Try must learn करा