1 / 11

13.4 Hash Tables

Name : Dhaval Shah Class Id : 219 Subject – CS257 Database System Principles Section-2. 13.4 Hash Tables. Hash Table. Useful as indexes. Used as main-memory data-structure. Uses Hash function, takes a search key (Hash key) as an argument and gives the integer between 0 to B-1.

king
Download Presentation

13.4 Hash Tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Name : Dhaval Shah Class Id : 219 Subject – CS257 Database System Principles Section-2 13.4 Hash Tables

  2. Hash Table • Useful as indexes. • Used as main-memory data-structure. • Uses Hash function, takes a search key (Hash key) as an argument and gives the integer between 0 to B-1. • Bucket array – an array indexed from 0 to B-1, and holds the headers of linked lists, one for each bucket of the array.

  3. Secondary-Storage Hash Tables • Hash table holds a very large no of records, that must be kept in secondary storage. • Bucket array consists of a blocks • Hashed records belong to the certain bucket are put in the block for that bucket. • If bucket overflows, then a chain of overflow block can be added to the bucket to hold more records.

  4. Example : Block can contain two records B=4, Key letters = a to f h(d) = 0, h(c) = h(e)=1, h(b) = 2, h(a) = h(f) = 3 Hash Table

  5. Hash Function • Hash function should ‘hash’ the key so the resulting integer is a seemingly random function of the key. • Hash function for integers : h(K) = remainder of K/B where K = key value, B = no of buckets • Hash function for character search keys: Treat Each character as an integer, sum these integers, and take the remainder when sum is divided by B

  6. Insertion Into a Hash Table • If want to insert new record with the search key K • Compute h(K) • If bucket number h(K) has space then insert it into the block for these bucket or one of the overflow block of the chain • If there is no room, we add new overflow block to the chain and store the new record there.

  7. Insertion into Hast-Table • Example : record with key g want to insert h(g) = 1 Adding addition block to a hash-table bucket

  8. Hast-Table Deletion • Deletion of record with key K • Go to Bucket No h(K) and search for the record with that key K. • Delete record with key K. • Move the records around among blocks so optionally consolidate the blocks of a chain into the fewer blocks.

  9. Example : • Delete the record with key c. • h(c) = 1 Result of Deletion from a hash table

  10. Efficiency of the Hast Table Indexes • If the No of records are less and there are enough buckets then this secondary storage hash-table method is efficient. • If the file grows, then we need to search long list of buckets. • This hast table is static. • There are many types of dynamic table where B is allowed to vary • 1) Extensible hashing • 2) Linear hashing

  11. Thank You

More Related