String Flashcards
Z algorithm - time and space complexity (prefix and string matching)
String matching:
Time: O(n+m)
Space: O(n+m)
Where n is the length of the pattern and m is the length of the text
Prefix:
Time: O(n)
Space: O(n)
Where n is the length of the string
Z algorithm (string matching) - how does it works
1) combine text and pattern with a special character (eg $&@“) which does not exist in both string
2) create z array with the algorithm
How does the algorithm form the z array: google of you forget
3) count the number of x(length of the pattern) in the array
4) that’s the answer
Z algorithm (prefix matching) - what it’s going to do
Find substring which is also the prefix of the original string
Manacher’s algorithm (longest palindromic substring)
- time and space complexity
Time: O(n) - linear
Space: O(n)
Where n is the length of the given string