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.
String Abstract Data TypeTimothy J. Ham
Western Michigan UniversityApril 23, 2010
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)
Where is it found?Strings are used in a number of places:
Page / window titlesWeb page / document titlesWeb page / document body text
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
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
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
Simple / Exhaustive
Simple / Exhaustive
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
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!
Knuth-Morris-Pratt
Knuth-Morris-Pratt
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
Knuth-Morris-PrattTheoretical run time is O(len(S) )*
*Assuming failure function has been previously run
Actual run time??? LET’S FIND OUT!!!
Conclusion
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
Thanks for being such a great audience!