COMPUTER 2430 Object Oriented Programming and Data Structures I
Handling Collision Linear Probe (Open Addressing): Go to the next available slot (circular) Double Hashing: Use a second hashing function if collision occurs (circular) Buckets Each array slot points to an array (2-D array) Quiz is coming? Program due! 2 2 2
Double Hashing First Hashing Function h1: index = h1(key) = key % table_size Second Hashing Function h2 for collision: step = h2(key) = 1 + key % AnotherPrime Quiz is coming? Program due! 3 3 3 3
Twin Primes 11 and 13 17 and 19 1229 and 1231 Donald Knuth Table size : the larger one AnotherPrime: the smaller one Quiz is coming? Program due! 4 4 4 4
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 21
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 21 60 21
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 60 21 60 86 21
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 60 86 21 60 86 21 23
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 60 86 21 23 60 86 75 21 23
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 60 86 75 21 23 62 60 86 75 21 23
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 62 60 86 75 21 23 62 60 86 32 75 21 23
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 62 60 86 32 75 21 23 62 60 86 32 75 21 23 45
Example/Exercise Index = h1(key) = key % 13 Step = h2(key) = 1 + key % 11 Key : 21 60 86 23 75 62 32 45 58 Index: ? ? ? ? ? ? ? ? ? 8 8 8 10 10 10 6 6 6 Step : ? ? ? ? ? ? ? ? ? 11 6 10 2 10 8 11 2 4 62 60 86 32 75 21 23 45 62 60 86 32 75 21 58 23 45
Quiz 6 Wednesday, December 5 Binary Search Hashing Counting
Prog 6 Group sign up Plan in SE Tool By 11:50 am Three students a group if possible Plan in SE Tool By 11 pm Monday Group discussion to agree Each student enters his/her plan