Timothy J. Ham Western Michigan University April 23, 2010.
-
Upload
corey-lawson -
Category
Documents
-
view
213 -
download
0
Transcript of Timothy J. Ham Western Michigan University April 23, 2010.
![Page 1: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/1.jpg)
String Abstract Data TypeTimothy J. Ham
Western Michigan UniversityApril 23, 2010
![Page 2: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/2.jpg)
What is it?Quite literally, the string abstract data type is
"an array of [characters]. The array consists of the string characters followed by the null character which signals the end of the string." (Textbook, p104, 2.6 para 3)
![Page 3: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/3.jpg)
Where is it found?Strings are used in a number of places:
Page / window titlesWeb page / document titlesWeb page / document body text
![Page 4: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/4.jpg)
What can I do with it?One of the most common operations performed on strings
is the search. There are a number of places in which this operation is employed:
Operating systems -> File names
Word processors -> Text documents
Web pages -> Body text**Anyone ever use the "Find" feature in Firefox that
searches as you type?
Databases -> Miscellaneous data
![Page 5: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/5.jpg)
How does this occur?The searches are performed using one of
several algorithms; this presentation will compare a simple and a complex string search algorithm:Exhaustive - easy to code, but very inefficientKnuth-Morris-Pratt - much more efficient than
simple algorithm
![Page 6: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/6.jpg)
How will we test this? The environment for testing these algorithms
will feature a string to search, as well as a pattern of characters for which we will search
In addition to providing the theoretical run time, we will measure the actual time (in milliseconds) required to run the algorithm
![Page 7: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/7.jpg)
Simple / Exhaustive
![Page 8: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/8.jpg)
Simple / Exhaustive
![Page 9: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/9.jpg)
Simple / ExhaustiveEasy to code; largely inefficientTheoretical run time is O( len(P) * len(S) ):
Len(P) is the length of the pattern for which we are searching
Len(S) is the length of the string we are searching
![Page 10: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/10.jpg)
Simple / ExhaustiveStarting with the first character, attempts to
match pattern; when it encounters a mismatch, it repeats the entire “matching” attempt with the next character
Actual run time??? LET’S FIND OUT!
![Page 11: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/11.jpg)
Knuth-Morris-Pratt
![Page 12: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/12.jpg)
Knuth-Morris-Pratt
![Page 13: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/13.jpg)
Knuth-Morris-PrattMore complex to code; shorter run timeInstead of starting over every time it
encounters a mismatch:the algorithm “remembers” how far along the
string it matched the patternfrom there, it attempts to match again
![Page 14: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/14.jpg)
Knuth-Morris-PrattTheoretical run time is O(len(S) )*
*Assuming failure function has been previously run
Actual run time??? LET’S FIND OUT!!!
![Page 15: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/15.jpg)
Conclusion
![Page 16: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/16.jpg)
ConclusionThe string abstract data type is found in
many placesWithout it, many search functions we take for
granted would not be possibleWhile a more complex searching algorithm
may be more difficult to code, it brings great rewards in time and energy efficiency
![Page 17: Timothy J. Ham Western Michigan University April 23, 2010.](https://reader035.fdocuments.us/reader035/viewer/2022062720/56649f065503460f94c1c6e4/html5/thumbnails/17.jpg)
Thanks for being such a great audience!