Hash_Table_v2

# Hash_Table_v2 - HashTable March302009 COP3502,UCF 1 Outline...

This preview shows pages 1–10. Sign up to view the full content.

Hash Table March 30 2009 COP 3502, UCF 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Outline Hash Table: Motivation Direct Access Table Hash Table Solutions for Collision Problem: Open Addressing: Linear Probing Quadratic Probing Dynamic Table Expansion Separate Chaining 2
Motivation We have to store some records and  perform the following: add new records delete records search a record by key Find a way to do these efficiently! key record Other  fields   containing associated data 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Record Example 9903030 0056789 0012345 0033333 tom david andy betty 73 56.8 81.5 90 sid (key) name score 9908080 bill 49 ... Consider this problem.  We want to store 1,000  student records and search them by student id. ... 4
Existing Data Structures Use an array to store the records, in unsorted  order add - add the records as the last entry,  very   fast   O(1) delete a target -  slow  at finding the target,  fast   at filling  the hole (just take the last entry)  O(n) search - sequential search,  slow  O(n) Use an array to store the records, keeping them in  sorted order add - insert the record in proper position, much record  movement,  slow  O(n) delete a target - how to handle the hole after deletion?  Much record movement,  slow  O(n) search - binary search,  fast   O(log n) 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Existing Data Structures Binary Search Tree: add: insert the record in proper position,  fast   O(logn) delete a target:  fast   O(logn) search:  fast   O(logn) 6
Direct Access Table : 33333 : 12345 0 : : betty : andy : : 90 : 81.5 : name score 56789 david 56.8 : 9908080 : : : bill : : : 49 : : 9999999 One way is to store the records  in a huge array (index  0..9999999)  The index is used  as the student id, i.e. the  record of the student with sid  0012345 is stored at A[12345] 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Direct Access Table Pros: add-  very fast   O(1) delete –  very fast   O(1) search –  very fast   O(1) Cons: Waste a lot of memory.  Use a table of TEN MILLION entries to store  ONE THOUSAND records.  8
Hash Function Imagine that we have such a  magic function  Hash .  It maps the  key (sid) of the 1000 records into  the integers 0. .999,  one to one .   No two different keys maps to the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## Hash_Table_v2 - HashTable March302009 COP3502,UCF 1 Outline...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online