Lecture 5 - KMP Flashcards

1
Q

What does KMP stand for?

A

Knuth Morris Pratt (algorithm)

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

What kind of an algorithm is KMP? hint : on

A

An online algorithm, this means it has no need to back up in the text. It instead involves preprocessing of the border table.

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

What is a border table?

A

an array b with entry b[j] for each position j of the string

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

What happens if we get a mismatch?

A

we remain on the current text character and compare it to a character which is determined by the border table

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

What is a suffix?

A

substring that ends at n-1 of string

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

What is a prefix?

A

substring that begins at position 0

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

What is the border of the table?

A

A border of the string s is a substring that is both a prefix and a suffix, but it cannot be the string itself

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

What are the borders of acac gat acac?

A

ac and acac are both borders. acac being the longest one

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

What is the border of an empty string?

A

an empty string itself is the border (length 0)

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

What is the size of the border table

A

Same size as the string we are looking for.

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

What is b[j] of the border table?

A

It holds the longest border of substring 0 to j-1

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

What is b[0] always set to ?

A

0, as this refers to a substring of size 0 i.e. sub[0..0]

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

fill in the border table of ababaca

A

0 0 0 1 2 3 0

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

After mismatch what happens in the KMP algorithm visually?

A

the string s gets shifted left until the characters to the left of i (current position in t) match the characters of s to the left of i. This essentially determines what j becomes (j is the index of the string )

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

Is it often that border tables of strings can be created?

A

NO

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

What happens if we cannot get a border match after a mismatch?

A

We need to reset j to 0 (start checking from the beginning of the string), while i will remain unchanged.

EDGE CASE if j is already 0 , i.e. first char of string, then instead increment i by 1.

17
Q

What is the complexity of the KMP algorithm?

A

O(n) in the worst case, as the number of the interations of the loop is at most 2n, this is because i and k always increase.

-> refer to slides
-> this is O(m+n) when combined with algorithm to create border table (the efficient one)

18
Q

Why is KMP better than the brute force approach?

A

As we avoid matching characters we know will match.

19
Q

What is the complexity of creating the border table?

A

O(j^2) to evaluate each length, then O(m) to evaluate all chars
hence O(m^3) overall

-> there are better approaches, refer to live lecture from week 5

20
Q

LOOK OVER THE COMPLEXITY FOR BORDER TABLE CREATION

A