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

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

View Full Document Right Arrow Icon
Hash Table March 30 2009 COP 3502, UCF 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 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 
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

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 Right Arrow Icon
Ask a homework question - tutors are online