This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Symbol Table ADT Hashing Symbol Table Implementations Binary Search Insert O(1) O(1) O(N) O(log(N)) Search O(1) O(N) O(log(N)) O(log(N)) KeyIndexed Array Sequential Search Balanced BST Recall the KeyIndexed Array ● It uses the search key as an array index – No comparison operation. ● Constraints of Key values – Distinct – Nonnegative integers – Range of should be small Hash Tables ● Similar to Keyindex array – Maps search key to array index (also called table address ) ● Main Components – Hash function that transforms the search key to a table address – Collisionresolution for keys that map to the same address ● Balance Between speed and memory – More key mappings , Less collision (faster) – More key mappings , More memory Hash Function Characteristics ● Hash function h(k) – k = Key data – Map k to M table addresses – Transform k into integers in the range [ , M  1 ] ● Ideal hash functions – Easy to compute – Every outcome is equally likely (random function) Hash Function 1 (float data) ● Keys: – Data: floating point – Range: (0,1) greater than 0, less than 1 ● Hash function: – floor(k * M) – Round down to integer (remove decimal) ● Example: – M = 50 k: 0.00 to 1.00 Key 1: 0.98 Table Address: 49 Key 1: 0.456 Table Address: 22 Key 1: 0.01 Table Address: Key 1: 0.32 Table Address: 16 Hash Function 2 (float data) ● Keys: – Data: floating point – Range: (s,t) greater than s, less than t ● Hash function: – M * (k – s)/(t  s) – (k – s)/(t – s) is used to generate a number ( , 1 ) ● Example: – M = 50 k: 0.50 to 1.00 Key 1: 0.98 Table Address: 48 Key 1: 0.651 Table Address: 15 Key 1: 0.71 Table Address: 21 Key 1: 0.532 Table Address: 3 Hash Function 3 (wbit integer) ● Keys: – Data: wbit integers – Range: [0, 2 w ) ● Hash function: – M * k/2 w watch out for data overflow (data range) – M * (k>>w) ● Example: – M = 50 k: 8bit integers [0, 256) Key 1: 5 Table Address: Key 1: 125 Table Address: 24 Key 1: 65 Table Address: 12 Key 1: 98 Table Address: 19 Hash Function 4 (wbit integer) ● Keys: – Data: wbit integers – Range: [0, 2 w ) ● Hash function: – k mod M (k % M) – a.k.a Modular Hash Function ● Example: – M = 50 k: 8bit integers [0, 256) Key 1: 5 Table Address: 5 Key 1: 125 Table Address: 25 Key 1: 65 Table Address: 15 Key 1: 98 Table Address: 48 Hash Function 5 (float data) ● Keys: – Data: floating point – Range: (s,t) greater than s, less than t ● Hash function: – floor(2 w * (k – s)/(t  s)) mod M – floor(2 w * (k – s)/(t – s)) => range [0, 2 w ) ● Example: – M = 50 k: 0.5 to 1.00 (use w=8) Key 1: 0.98 Table Address: 45 Key 1: 0.651 Table Address: 27 Key 1: 0.71 Table Address: 7 Key 1: 0.532 Table Address: 15 Modular hash function ● Reduces the probability of collision ● Table size, M, is set to a prime number ● Alternative Function – – Use an arbitrary value for ● Popular choice: golder ratio h k = ⌊ k ⌋ modM = 0.618033... Handling long keys...
View
Full
Document
This note was uploaded on 01/13/2011 for the course EEEI 13 taught by Professor Ramos during the Winter '10 term at University of the Philippines Diliman.
 Winter '10
 Ramos

Click to edit the document details