Substring search Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the brute force approach for SS search?

A

Keep main pointer i, and pattern pointer j, for each i increment j until finding mismatch or reaching end of pattern.

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

What is the alternative brute force approach?

A

If main pointer i matches j, increment j. If they do not, send i back amount of mismatches indices given by j and reset j to 0.
If fonmd, return main i - pattern length

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

What is the worst case for brute force search?

A

Requires NM compares when both pattern and text are all A’s followed by a B.
For each N-M+1 possible match, all characters are cecked against text.

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

How do you search manually with KMP?

A

If mismatch, find prefix that is also suffix and allign with next occurance in text.

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

What are the steps for the RKF?

A
  1. Compute hash value for pattern
  2. Compute tvalue of R^(M-1)mod Q
  3. Use hashSearch():
    * Compuite hash function for first M chars and compare against pattern hash
    * If not match, proceed through text and compute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the RKM work?

A

Hash = tiR^(m-1) +…+ t(i+m-1)R^0
For the next position, we can calculate this by subtracting the contribution of the first character, times it with R and add the contribution of the next. We then mod this with Q. This computation is done in constant time.

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