hashing-102-sp10

hashing-102-sp10 - Hashing Text Read Weiss, 5.1 5.5 Goal...

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

View Full Document Right Arrow Icon
Hashing Text Read Weiss, §5.1 – 5.5 Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining Open addressing: linear probing , quadratic probing , double hashing Rehashing Load factor
Background image of page 1

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

View Full DocumentRight Arrow Icon
Tree Structures Binary Search Trees AVL Trees
Background image of page 2
Tree Structures insert / delete / find worst average Binary Search Trees N log N AVL Trees log N
Background image of page 3

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

View Full DocumentRight Arrow Icon
Goal Develop a structure that will allow user to insert/delete/find records in constant average time structure will be a table (relatively small) table completely contained in memory implemented by an array capitalizes on ability to access any element of the array in constant time
Background image of page 4
Hash Function Determines position of key in the array. Assume table (array) size is N Function f(x) maps any key x to an int between 0 and N− 1 For example, assume that N= 15, that key x is a non-negative integer between 0 and MAX_INT, and hash function f(x) = x % 15. (Hash functions for strings aggregate the character values --- see Weiss §5.2.)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Hash Function Let f(x) = x % 15. Then, if x = 25 129 35 2501 47 36 f(x) = 10 9 5 11 2 6 Storing the keys in the array is straightforward: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 _ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _ Thus, delete and find can be done in O(1), and
Background image of page 6
Hash Function What happens when you try to insert: x = 65 ? x = 65 f(x) = 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 _ _ 47 _ _ 35 36 _ _ 129 25 2501 _ _ _ 65(?) This is called a collision .
Background image of page 7

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

View Full DocumentRight Arrow Icon
Handling Collisions Separate Chaining Open Addressing Linear Probing Quadratic Probing Double Hashing
Background image of page 8
Handling Collisions Separate Chaining
Background image of page 9

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

View Full DocumentRight Arrow Icon
Separate Chaining Let each array element be the head of a chain. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 47 65 36 129 25 2501 35 Where would you store: 29, 16, 14, 99, 127 ?
Background image of page 10
Separate Chaining Let each array element be the head of a chain: Where would you store: 29, 16, 14, 99, 127 ? 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 47 65 36 127 99 25 2501 14 35 129 29 New keys go at the front of the relevant chain.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Separate Chaining: Disadvantages Parts of the array might never be used. As chains get longer, search time increases to O(n) in the worst case. Constructing new chain nodes is relatively
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/06/2010 for the course COMPUTER S 101 taught by Professor Sanaodeh during the Spring '08 term at NYU.

Page1 / 46

hashing-102-sp10 - Hashing Text Read Weiss, 5.1 5.5 Goal...

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

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