


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Design and Analysis of Algorithms - Chapter 7 1
http://www.cse.unl.edu/~goddard/Courses/CSCE310J
Design and Analysis of Algorithms - Chapter 7 2
Design and Analysis of Algorithms - Chapter 7 3
Design and Analysis of Algorithms - Chapter 7 4
Design and Analysis of Algorithms - Chapter 7 5
1970: Cook shows (using finite-state machines) that problem can be solved in time proportional to n + m
1976 Knuth and Pratt find algorithm based on Cook’s idea; Morris independently discovers same algorithm in attempt to avoid “backing up” over text
At about the same time Boyer and Moore find an algorithm that examines only a fraction of the text in most cases (by comparing characters in pattern and text from right to left, instead of left to right)
1980 Another algorithm proposed by Rabin and Karp virtually always runs in time proportional to n + m and has the advantage of extending easily to two-dimensional pattern matching and being almost as simple as the brute-force method.
Design and Analysis of Algorithms - Chapter 7 6
Design and Analysis of Algorithms - Chapter 7 7
Look at first (rightmost) character in text that was compared. Three cases:
.....A...................... ( A occurs twice in pattern) BAOBAB
Design and Analysis of Algorithms - Chapter 7 8
Design and Analysis of Algorithms - Chapter 7 9
Design and Analysis of Algorithms - Chapter 7 10
Design and Analysis of Algorithms - Chapter 7 11
Design and Analysis of Algorithms - Chapter 7 12
Imagine that we could assign a unique array index to every possible key that could occur in an application.
Design and Analysis of Algorithms - Chapter 7 19
"
Basic Operation: comparisons
1 1
= = h h
n n n nh
i h nh
i n
An
n
i
n
i
s
Design and Analysis of Algorithms - Chapter 7 20
"
Design and Analysis of Algorithms - Chapter 7 21
All elements are stored in the array of the hash table, rather than using linked lists to accommodate collisions
/ $
» h = 8, initially j = i = 4 » rehash( j ) = ( j +1) mod h » rehash(4) = (4+1) mod 8 = 5 // collision again » rehash(5) = (5+1) mod 8 = 6 // collision again » … put in 7
Design and Analysis of Algorithms - Chapter 7 23
0 1 -
Design and Analysis of Algorithms - Chapter 7 24
"
α α α
ln