Hash - 1 Hashing - Introduction z Hashing is a technique...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 Hashing - Introduction z Hashing is a technique used for performing insertions , deletions and finds in constant average time. z Tree operations that require any ordering information among the elements are not supported efficiently. – See several methods of implementing the hash table. – Compare these methods analytically. – Show numerous applications of hashing. – Compare hash tables with binary search trees. 2 Why Hash Table? z Often, array indices are not natural identifiers for items that are to be stored, accessed, and retrieved. z For example, let’s try to store the list in an array. beef bellpepper blackpepper dillweed onion potato olive salt cumin carrot mushroom tomatopaste 3 Problem z It is true that STORE and RETRIEVE are O (1) operations for arrays, that is only so if the indices are known and the value in the target of a STORE can be discarded. z Without a complete set in hand it cannot be known that potato has index 10 in the sorted list of items. 4 Solution z Use item as a KEY--Because an index integer is not known on the entry of an item, it would be helpful if the item itself could be used as a key to index the cell where it will be stored. 5 Solution z A solution would be to convert the keys (the items) into unique integers and use them as array indices. z A function that does so is called a hash function . z The conversion process is called hashing z The storage structure is called a hash table or scatter-storage . 6 Example Solution z We may sum up the ASCII value from each character in the key, e.g., a = 1, b=2, …, z = 26, so beef = 2+5+5+6=18. Item HF1(Item) Item HF1(Item) beef 18 carrot 75 onion 67 salt 52 cumin 60 blackpepper 105 dillweed 74 olive 63 bellpepper 107 tomatopaste 145 potato 87 mushroom 122 7 General Idea z Hash table data structure is merely an array of some fixed size, containing the keys. z A key is a string with an associated value (e.g., salary information). z Each key is mapped into a num in the range ( , H_SIZE – 1) and placed in the cell. f : key → index 8 General Idea z The mapping is called a hash function , which ideally should be simple to compute and should ensure that any two distinct keys get different cells. z This is difficult to achieve in reality since there are a finite number of cells and a virtually inexhaustible supply of keys. z We seek a hash function that distributes the keys evenly among the cells. 9 Issues z Choosing the hashing function – How to make sure that one has selected a good function for the application z Collision handling – How to handle conflict when two keys have the same location z Deletion handling – How to deal with the table when items are being removed 10 Example 11 Hash Tables z The idea of a hash table is to allow many of the different possible keys that might occur to be mapped to the locations in an array under the action of the index function....
View Full Document

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 67

Hash - 1 Hashing - Introduction z Hashing is a technique...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online