# DS07_Ch07a - CHAPTER 7 HASHING What is hashing for For...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CHAPTER 7 HASHING What is hashing for? For searching But we already have binary search in O( ln n ) time after sorting. And we already have algorithms for sorting in optimal time O( n ln n )... Wait a minute — who said that O( n ln n ) is the optimal time? There’s a theorem saying that “Any algorithm that sorts by comparisons only must have a worst case computing time of Ω ( n log 2 n ).” Then we just do something else besides comparison. Interpolation Search : Find key from a sorted list f [ l ].key , f [ l+1 ].key , ... , f [ u ].key . f[l].key f[u].key l u key i ? n elements l i key l f key n key l f key u f--- = ]. [ ]. [ ]. [ key l f key u f n key l f key l i ]. [ ]. [ ) ]. [ (- ⋅- + = ⇒ If ( f [ i ].key < key ) l = i ; Else u = i ; Search by Formula Search by Formula 1/14 §1 General Idea Symbol Table ( == Dictionary) ::= { < name, attribute > } 〖 Example 〖 In Oxford English dictionary name = since attribute = a list of meanings M[0] = after a date, event, etc. M[1] = seeing that (expressing reason) …… …… This is the worst disaster in California since I was elected. California Governor Pat Brown, discussing a local flood 〖 Example 〖 In a symbol table for a compiler name = identifier (e.g. int ) attribute = a list of lines that use the identifier, and some other fields 2/14 Objects : A set of name-attribute pairs, where the names are unique Operations : SymTab Create(TableSize) Boolean IsIn(symtab, name) Attribute Find(symtab, name) SymTab Insert(symtab, name, attr) SymTab Delete(symtab, name) Symbol Table ADT: §1 General Idea 3/14 Hash Tables [0] [1] … … [s- 1] … … ht [ 0 ] … … ht [ 1 ] … … ht [b- 1] … … … … b buckets s slots For each identifier x , we define a hash function f ( x ) = position of x in ht[ ] (i.e....
View Full Document

## This note was uploaded on 10/20/2011 for the course COMPUTER S 10586 taught by Professor Jilinwang during the Spring '09 term at Zhejiang University.

### Page1 / 14

DS07_Ch07a - CHAPTER 7 HASHING What is hashing for For...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online