String Flashcards

1
Q

Z algorithm - time and space complexity (prefix and string matching)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Z algorithm (string matching) - how does it works

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Z algorithm (prefix matching) - what it’s going to do

A

Find substring which is also the prefix of the original string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Manacher’s algorithm (longest palindromic substring)

- time and space complexity

A

Time: O(n) - linear
Space: O(n)
Where n is the length of the given string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly