60 likes | 166 Views
COP 3402 Systems Programming. Dr. Ali Orooji School of EECS University of Central Florida. SEARCHING n = number of elements. Binary Search average number of comparisons =
E N D
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida
SRCH - SEARCHING n = number of elements Binary Search average number of comparisons = n = 1,000 ==> avg = = 10 n = 1,000,000 ==> avg = 20 Linear Searchaverage number of comparisons = n/2 n = 1,000 ==> avg = 1000 / 2 = 500 n = 1,000,000 ==> avg = 500,000
SRCH - Hashing tries to do searching with only one comparison when storing when searching
425 ==> 25 100 SRCH - Hash Functions Division Method ==> remainder Mid-Square Method (key) = - - - - - - - - (key) = 75637809 key table size 2 2
425 225 ==> ==> 25 25 100 100 SRCH - Hash Collision key 1 key 2 Resolving Hash Collision Linear Probing e.g., use next available one Linear probing is an example of a general method for resolving hash collisions called rehashing or open addressing. hash same address hash 25 425 225
25 425 225 Bucket Directory (Hash Index) 225 25 425 SRCH - Chaining if new nodes are added to the beginning of the linked list “good” hash functions have very few hash collisions