Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 13 Hash Tables Section 13.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112.

Similar presentations


Presentation on theme: "Chapter 13 Hash Tables Section 13.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112."— Presentation transcript:

1 Chapter 13 Hash Tables Section 13.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112

2 Agenda Secondary Storage Hash tables Secondary Storage Hash tables Insertion into hash table Insertion into hash table Deletion of hash table Deletion of hash table Extensible hash tables Extensible hash tables

3 Secondary Storage Hash tables Secondary memory needed to store hash tables with very large records Secondary memory needed to store hash tables with very large records Same as main memory hash tables Same as main memory hash tables In secondary hash bucket arrays consists of block rather then pointer to headers In secondary hash bucket arrays consists of block rather then pointer to headers When bucket arrays overflow, chain bucket can be added When bucket arrays overflow, chain bucket can be added

4 Secondary Storage Hash tables (cont…) Hash function h(k) takes k argument (search key) Hash function h(k) takes k argument (search key) h(k) computes the bucket locations in hash table h(k) computes the bucket locations in hash table Example: hash table with 4 buckets and search key in each bucket each bucket with overflow bucket where new bucket can be added is called “NUB” 0d 1e c 2b 3a f

5 Insertion into Hash tables (cont…) Based on search key k hash function h gives bucket number Based on search key k hash function h gives bucket number h(d) = 0, h(e)=h(c)=1… h(d) = 0, h(e)=h(c)=1… When new record needs to be inserted for example record with key m When new record needs to be inserted for example record with key m Hash function h(m) calculates and gives location Hash function h(m) calculates and gives location Lets say h(m) = 2 then record with search key m will be inserted into bucket 2 Lets say h(m) = 2 then record with search key m will be inserted into bucket 2 If that bucket is full then new overflow bucket is inserted at the NUB and record then be inserted in it If that bucket is full then new overflow bucket is inserted at the NUB and record then be inserted in it 0d 1e c 2b 3a f g

6 Insertion into Hash tables (cont…) Deleting record from the hash table performed by providing search key and getting the bucket number and deleting that record Deleting record from the hash table performed by providing search key and getting the bucket number and deleting that record If record is deleted and any overflowed bucket associated with that bucket then the record from the overflowed gets moved to that bucket If record is deleted and any overflowed bucket associated with that bucket then the record from the overflowed gets moved to that bucket For example: delete record with key c as shown below before deleteafter delete 0d 1e c 2b 3a f g 0d1e g 2b 3a f

7 Insertion into Hash tables (cont…) Deleting record from the hash table performed by providing search key and getting the bucket number and deleting that record Deleting record from the hash table performed by providing search key and getting the bucket number and deleting that record If record is deleted and any overflowed bucket associated with that bucket then the record from the overflowed gets moved to that bucket If record is deleted and any overflowed bucket associated with that bucket then the record from the overflowed gets moved to that bucket For example: delete record with key c as shown below before deleteafter delete 0d 1e c 2b 3a f g 0d1e g 2b 3a f

8 Extensible Hash tables level of indirection used for buckets level of indirection used for buckets Array of pointers to block represents buckets Array of pointers to block represents buckets Array of pointers can grow with length power of 2 growing the no. of buckets to double Array of pointers can grow with length power of 2 growing the no. of buckets to double provides dynamic hashing because of array pointers provides dynamic hashing because of array pointers 00011 00011 i =1 0 1


Download ppt "Chapter 13 Hash Tables Section 13.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID - 112."

Similar presentations


Ads by Google