Newest Viewed Downloaded

Hash Table DesignDynamic resizing of table. Whenever loading density exceeds threshold (4/5 in our example), rehash into a table of approximately twice the current size. Fixed table size. Know maximum number of pairs. No more than 1000 pairs. Loading density <= 4/5 => b >= 5/4*1000 = 1250. Pick b (equal to divisor) to be a prime number or an odd number with no prime divisors smaller than 20.

Overflow Handling

An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by: Search the hash table in some systematic fashion for a bucket that is not full. Linear probing (linear open addressing). Quadratic probing. Random probing. Eliminate overflows by permitting each bucket to keep a list of all pairs for which it is the home bucket. Array linear list. Chain.

Linear Probing – Get And Put

0 4 8 12 16 Put in pairs whose keys are 6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 6 12 29 34 28 11 23 7 0 33 30 45 search the table for the next available bucket divisor = b (number of buckets) = 17. Home bucket = key % 17.

Linear Probing -- Remove

0 4 8 12 16 6 12 29 34 28 11 23 7 0 33 30 45 0 4 8 12 16 6 12 29 34 28 11 23 7 45 33 30 Search cluster for pair (if any) to fill vacated bucket. 0 4 8 12 16 6 12 29 34 28 11 23 7 45 33 30 remove(0)

Linear Probing – remove(34)

0 4 8 12 16 6 12 29 34 28 11 23 7 0 33 30 45 0 4 8 12 16 6 12 29 0 28 11 23 7 33 30 45 0 4 8 12 16 6 12 29 0 28 11 23 7 33 30 45 0 4 8 12 16 6 12 29 28 11 23 7 0 33 30 45 Search cluster for pair (if any) to fill vacated bucket.

Linear Probing – remove(29)

0 4 8 12 16 6 12 29 34 28 11 23 7 0 33 30 45 0 4 8 12 16 6 12 34 28 11 23 7 0 33 30 45 0 4 8 12 16 6 12 11 34 28 23 7 0 33 30 45 0 4 8 12 16 6 12 11 34 28 23 7 0 33 30 45 0 4 8 12 16 6 12 11 34 28 23 7 0 33 30 45 Search cluster for pair (if any) to fill vacated bucket.

Performance Of Linear Probing

0 4 8 12 16 6 12 29 34 28 11 23 7 0 33 30 45 Worst-case get/put/remove time is (n), where n is the number of pairs in the table. This happens when all pairs are in the same cluster.

Expected Performance

0 4 8 12 16 6 12 29 34 28 11 23 7 0 33 30 45 α = loading density = (number of pairs)/b. α = 12/17. Sn = expected number of buckets examined in a successful search when n is large Un = expected number of buckets examined in a unsuccessful search when n is large Time to put and remove governed by Un. A put that increases the number of pairs in the table involves an unsuccessful search followed by the addition of an element. An unsuccessful remove is essentially an unsuccessful search.

Expected Performance

α <= 0.75 is recommended. Sn ~ ½(1 + 1/(1 – α )) Un ~ ½(1 + 1/(1 – α )2) Note that 0 <= α <= 1.

Hash Table Design

Performance requirements are given, determine maximum permissible loading density. We want a successful search to make no more than 10 compares (expected). Sn ~ ½(1 + 1/(1 – α )) α <= 18/19 We want an unsuccessful search to make no more than 13 compares (expected). Un ~ ½(1 + 1/(1 – α )2) α <= 4/5 So α <= min{18/19, 4/5} = 4/5.

Hash Table Design

Dynamic resizing of table. Whenever loading density exceeds threshold (4/5 in our example), rehash into a table of approximately twice the current size. Fixed table size. Know maximum number of pairs. No more than 1000 pairs. Loading density <= 4/5 => b >= 5/4*1000 = 1250. Pick b (equal to divisor) to be a prime number or an odd number with no prime divisors smaller than 20.

Hashing With Chains

Each bucket keeps a chain of all pairs for which it is the home bucket. The chain may or may not be sorted by key. Alternatively, each bucket has an array linear list.

Put in pairs whose keys are 6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 Home bucket = key % 17. Sorted Chains [0] [4] [8] [12] [16] 12 6 34 29 28 11 23 7 0 33 30 45 The chains may be sorted or unsorted (the text uses sorted chains).

Expected Performance

Note that α >= 0. Expected chain length is α . Sn ~ 1 + α /2. Un <= α , when α <= 1.

Showing 1 - 13 of 13 items Details

Name: 
mlec7-2
Author: 
Preferred Customer
Company: 
N/A
Description: 
Hash Table DesignDynamic resizing of table. Whenever loading density exceeds threshold (4/5 in our example), rehash into a table of approximately twice the current size. Fixed table size. Know maximum number of pairs. No more than 1000 pairs. Loading density <= 4/5 => b >= 5/4*1000 = 1250. Pick b (equal to divisor) to be a prime number or an odd number with no prime divisors smaller than 20.
Tags: 
bucket | the | linear | search | pairs | probing | number | table
Created: 
6/17/1995 11:31:02 PM
Slides: 
13
Views: 
0
Downloads: 
0
Rating: 
0


> Comment



Share this presentation
|

Comments

Share this presentation:

|
Sitemap