Skip to content

Commit 27f2f6f

Browse files
Added String topic in DSA
1 parent d39a024 commit 27f2f6f

File tree

4 files changed

+183
-3
lines changed

4 files changed

+183
-3
lines changed

docs/dsa/strings/_category_.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "String",
3+
"position": 8,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "In data structures, a string is a sequence of characters used to represent text. Strings are commonly used for storing and manipulating textual data in computer programs. They can be manipulated using various operations like concatenation, substring extraction, and comparison."
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Practice Problems for Strings
2+
3+
To further practice and test your understanding of strings, consider solving the following problems from LeetCode:
4+
5+
## Easy
6+
7+
1. [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)
8+
2. [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)
9+
3. [Implement strStr()](https://leetcode.com/problems/implement-strstr/)
10+
4. [Count and Say](https://leetcode.com/problems/count-and-say/)
11+
5. [Reverse String](https://leetcode.com/problems/reverse-string/)
12+
6. [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/)
13+
7. [Valid Anagram](https://leetcode.com/problems/valid-anagram/)
14+
8. [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/)
15+
9. [Detect Capital](https://leetcode.com/problems/detect-capital/)
16+
10. [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern/)
17+
18+
## Medium
19+
20+
11. [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)
21+
12. [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)
22+
13. [Group Anagrams](https://leetcode.com/problems/group-anagrams/)
23+
14. [Decode String](https://leetcode.com/problems/decode-string/)
24+
15. [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)
25+
16. [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)
26+
17. [Simplify Path](https://leetcode.com/problems/simplify-path/)
27+
18. [Add Bold Tag in String](https://leetcode.com/problems/add-bold-tag-in-string/)
28+
19. [Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)
29+
20. [Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/)
30+
31+
Engaging with these problems will help reinforce the concepts learned and provide practical experience in using strings effectively. By practicing these problems, you will enhance your problem-solving skills and deepen your understanding of string manipulation in various contexts.

docs/dsa/strings/strings-dsa.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
id: strings-in-dsa
3+
title: Strings in Data Structures and Algorithms
4+
sidebar_label: Strings
5+
sidebar_position: 1
6+
description: "A string is a sequence of characters. It is a data structure that represents a sequence of characters, either as a literal constant or as some kind of variable. In data structures and algorithms, strings are used in a wide range of applications such as text processing, pattern matching, and data serialization."
7+
tags:
8+
[
9+
dsa,
10+
data-structures,
11+
strings,
12+
string,
13+
string-data-structure,
14+
string-in-dsa,
15+
string-in-data-structure,
16+
string-in-algorithm,
17+
string-in-dsa-example,
18+
string-in-dsa-explanation,
19+
string-in-dsa-conclusion,
20+
string-in-dsa-importance,
21+
string-in-dsa-syntax,
22+
string-in-dsa-declaration,
23+
string-in-dsa-access,
24+
string-in-dsa-update,
25+
string-in-dsa-length,
26+
string-in-dsa-iterate,
27+
string-in-dsa-max-min,
28+
string-in-dsa-program,
29+
string-in-dsa-code,
30+
string-in-dsa-js,
31+
string-in-dsa-java,
32+
string-in-dsa-python,
33+
string-in-dsa-c,
34+
string-in-dsa-cpp,
35+
string-in-dsa-ts,
36+
]
37+
---
38+
39+
A string is a sequence of characters. It is a data structure that represents a sequence of characters, either as a literal constant or as some kind of variable. In data structures and algorithms, strings are used in a wide range of applications such as text processing, pattern matching, and data serialization.
40+
41+
## Why are Strings important?
42+
43+
Strings are important because they are used to store and manipulate text. They are used in many applications such as text processing, pattern matching, and data serialization.
44+
45+
## How to declare a String?
46+
47+
A string can be declared in various programming languages using the following syntax:
48+
49+
# Strings in Data Structures and Algorithms (DSA)
50+
51+
## Table of Contents
52+
53+
1. [Introduction](#introduction)
54+
2. [Basic String Operations](#basic-string-operations)
55+
3. [Pattern Matching Algorithms](#pattern-matching-algorithms)
56+
4. [String Manipulation](#string-manipulation)
57+
5. [String Data Structures](#string-data-structures)
58+
6. [Common String Problems](#common-string-problems)
59+
7. [Advanced String Algorithms](#advanced-string-algorithms)
60+
8. [Resources and References](#resources-and-references)
61+
62+
## Introduction
63+
64+
Strings are sequences of characters and are a fundamental data type in computer science. They are used extensively in algorithms and data structures.
65+
66+
## Basic String Operations
67+
68+
- **Length**: Determine the length of a string.
69+
- **Concatenation**: Combine two or more strings.
70+
- **Substring**: Extract a portion of a string.
71+
- **Comparison**: Compare two strings lexicographically.
72+
- **Search**: Find the occurrence of a substring.
73+
74+
## Pattern Matching Algorithms
75+
76+
- **Naive Pattern Matching**: A straightforward approach with a time complexity of O(m\*n).
77+
- **Knuth-Morris-Pratt (KMP)**: An efficient pattern matching algorithm with a time complexity of O(m+n).
78+
- **Rabin-Karp Algorithm**: Uses hashing for pattern matching with a time complexity of O(m+n) on average.
79+
- **Boyer-Moore Algorithm**: A powerful algorithm with a worst-case time complexity of O(m\*n) but performs well in practice.
80+
81+
## String Manipulation
82+
83+
- **Reversal**: Reversing a string.
84+
- **Palindromes**: Checking if a string reads the same forwards and backwards.
85+
- **Anagrams**: Checking if two strings are permutations of each other.
86+
- **Rotation**: Rotating a string by a given number of characters.
87+
88+
## String Data Structures
89+
90+
- **Trie (Prefix Tree)**: A tree-like data structure that stores a dynamic set of strings, typically used for search operations.
91+
- **Suffix Tree**: A compressed trie of all suffixes of a given string, useful for pattern matching.
92+
- **Suffix Array**: An array of all suffixes of a string, sorted in lexicographical order.
93+
- **Aho-Corasick Algorithm**: A trie-based data structure for multiple pattern matching.
94+
95+
## Common String Problems
96+
97+
- **Longest Common Substring**: Finding the longest substring that appears in two or more strings.
98+
- **Longest Common Subsequence**: Finding the longest sequence that can be derived from two strings without changing the order of characters.
99+
- **Edit Distance (Levenshtein Distance)**: Measuring the minimum number of single-character edits required to change one string into another.
100+
- **String Compression**: Reducing the size of a string using algorithms like Run-Length Encoding (RLE).
101+
102+
## Advanced String Algorithms
103+
104+
- **Burrows-Wheeler Transform (BWT)**: A data transformation algorithm useful for data compression.
105+
- **Manacher’s Algorithm**: An efficient algorithm to find the longest palindromic substring in linear time.
106+
- **Z-Algorithm**: Finds occurrences of a pattern in a string in linear time.
107+
108+
## Resources and References
109+
110+
- **Books**:
111+
- "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein
112+
- "Algorithms" by Robert Sedgewick and Kevin Wayne
113+
- **Online Courses**:
114+
- Coursera: Data Structures and Algorithm Specialization
115+
- edX: Algorithms and Data Structures
116+
- **Websites**:
117+
- [GeeksforGeeks](https://www.geeksforgeeks.org)
118+
- [LeetCode](https://leetcode.com)
119+
- [HackerRank](https://www.hackerrank.com)
120+
121+
---
122+
123+
By understanding and mastering these string concepts and algorithms, you will be well-equipped to tackle a wide range of problems in data structures and algorithms.
124+
125+
## Conclusion
126+
127+
Strings are a vital data structure in the study of data structures and algorithms (DSA). They are sequences of characters used to represent text and are fundamental to various programming tasks. In this tutorial, we explored the essential operations related to strings, including declaration, access, modification, length determination, iteration, and searching in different programming languages like JavaScript, Java, Python, C, C++, and TypeScript.
128+
129+
Understanding strings is crucial for solving numerous problems in computer science, from simple text manipulation to complex algorithms in text processing, pattern matching, and more. The examples provided demonstrate how to work with strings efficiently, ensuring a robust foundation for tackling more advanced DSA concepts. Mastery of strings enhances your ability to handle data and perform operations crucial in both everyday programming and competitive coding.
130+
131+
Problems for Practice
132+
To further practice and test your understanding of strings, consider solving the following problems from LeetCode:
133+
134+
1. Longest Substring Without Repeating Characters
135+
2. Valid Anagram
136+
3. Longest Palindromic Substring
137+
4. Group Anagrams
138+
5. Minimum Window Substring
139+
140+
Engaging with these problems will help reinforce the concepts learned and provide practical experience in using strings effectively. By practicing these problems, you will enhance your problem-solving skills and deepen your understanding of string manipulation in various contexts.

dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
id: Letter Combinations of a Phone Number
2+
id: letter-combinations-of-a-phone-number
33
title: Letter Combinations of a Phone Number (LeetCode)
4-
sidebar_label: 0017-Letter-Combinations-of-a-Phone-Number
4+
sidebar_label: 0017 Letter Combinations of a Phone Number
55
tags:
66
- Back Tracking
77
- Mapping
@@ -39,6 +39,7 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
3939
- **Output:** `["a","b","c"]`
4040

4141
### Constraints:
42+
4243
- `0 ≤ digits.length ≤ 4`
4344
- `0 ≤ digits.length ≤ 4digits[𝑖]`
4445
- `digits[i] is a digit in the range ['2', '9'].`
@@ -313,4 +314,4 @@ Here's a step-by-step algorithm for generating all possible letter combinations
313314
- Call the backtracking function with the initial index set to 0 and an empty string as the initial combination.
314315
- Return the list of combinations.
315316

316-
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
317+
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.

0 commit comments

Comments
 (0)