Presentation is loading. Please wait.

Presentation is loading. Please wait.

Timothy J. Ham Western Michigan University April 23, 2010.

Similar presentations


Presentation on theme: "Timothy J. Ham Western Michigan University April 23, 2010."— Presentation transcript:

1 Timothy J. Ham Western Michigan University April 23, 2010

2 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)

3 Where is it found? Strings are used in a number of places: Page / window titles Web page / document titles Web page / document body text

4 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

5 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 inefficient Knuth-Morris-Pratt - much more efficient than simple algorithm

6 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

7

8 Simple / Exhaustive

9 Easy to code; largely inefficient Theoretical 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

10 Simple / Exhaustive Starting 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!

11

12 Knuth-Morris-Pratt

13 More complex to code; shorter run time Instead of starting over every time it encounters a mismatch: the algorithm “remembers” how far along the string it matched the pattern from there, it attempts to match again

14 Knuth-Morris-Pratt Theoretical run time is O(len(S) )* *Assuming failure function has been previously run Actual run time??? LET’S FIND OUT!!!

15

16 Conclusion The string abstract data type is found in many places Without it, many search functions we take for granted would not be possible While a more complex searching algorithm may be more difficult to code, it brings great rewards in time and energy efficiency

17


Download ppt "Timothy J. Ham Western Michigan University April 23, 2010."

Similar presentations


Ads by Google