CS 228 meeting -*- Outline -*- * introduction to searching and hashing (HR 12.4-6) This section of chapter 12 studies the problem of associative retrieval, or searching in random access data structures. ** motivating question Q: How to find info associated with a key in a (online) database? ------------------------------------------ SEARCHING AND HASHING (HR 12.4-6) MOTIVATING PROBLEM Given a collection of records, retrieve the record with a given key. Example: A poison control hotline. Records are struct Poison { String name; // the key String treatment; }; ------------------------------------------ The hotline takes calls from people, after finding out the substance's name, reads the remedy to the caller. Have *lots* of poisons listed (hundreds of thousands). Since it's a nonprofit organization, it has an old, slow computer (:-) Want the lookup of a treatment to be fast. Less dramatic examples are also very common: getting information associated with a file name from a directory looking up telephone numbers etc. ** overview ------------------------------------------ SEARCHING AND HASHING OVERVIEW Techniques Time cost A. linear search O(N) B. binary search O(log N) C. hashing O(1) on average Key insight: Changing the data structure leads to qualitative improvements ------------------------------------------ the insight has very wide application! this is also the outline Caveat: because these use different data structures, need to use all of them at different times, so can't just, say, use hashing.