3.2- Sequential Search & Brute-Force String Matching Flashcards

1
Q

A simple extra trick is often employed
in implementing sequential search:

A

if we append the search key to the end of
the list, the search for the key will have to be successful, and therefore we can
eliminate the end of list check altogether.

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

improvement can be incorporated in sequential
search if

A

a given list is known to be sorted: searching in such a list can be stopped
as soon as an element greater than or equal to the search key is encountered.

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

Sequential search provides an excellent illustration of the brute-force approach,

A

with its characteristic strength (simplicity) and weakness (inferior efficiency).

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

given a string of n
characters called the_____ and a string of m characters (m ≤ n) called the______,
find a substring of the text that matches the pattern. To put it more precisely, we
want to find i—the index of the leftmost character of the first matching substring

A

text
pattern

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

A brute-force algorithm for the string-matching problem is quite obvious:
align the pattern against the first m characters of the text and start matching the
corresponding pairs of characters from left to right until either all the m pairs
of the characters match (then the algorithm can stop) or a mismatching pair is
encountered.

A

In the latter case, shift the pattern one position to the right and
resume the character comparisons, starting again with the first character of the
pattern and its counterpart in the text. Note that the last position in the text that
can still be a beginning of a matching substring is n − m(provided the text positions
are indexed from 0 to n − 1). Beyond that position, there are not enough characters
to match the entire pattern; hence, the algorithm need not make any comparisons
there.

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