cse101_10_10_11

Cse101_10_10_11 - Hashing 1 Goal a Want to store n items a.i In O(n space a.ii With O(1 lookup time a.iii O(1 insertion/deletion time b Say the

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

View Full Document Right Arrow Icon
Hashing 1. Goal a. Want to store n items: a.i. In O(n) space a.ii. With O(1) lookup time a.iii. O(1) insertion/deletion time b. Say the items to be stored are numbers in the range 0 to M – 1. Create a table T[0… n-1] Pick a hash function H:{0,1…,M-1} -> {0,1…n-1}. H(x) === x mod n. Table has linked list of all items that hash to I for collisions. Space: O(n) Lookup time: could be O(n) EX: want to store n = 300 social security numbers Pick random hash function because you can have a bad set of numbers c. No matter which hash function h: {0,1,…,M-1} -> {0,1,…,n-1} you pick, there will always be some set of n items S c {0,1,…,M-1} which result in O(n) lookup time – ie. The items all hash to the same slot. Box of all possible hash functions, pick randomly from hat space. all sets of n items (eg n SS #s) the chance of hitting a bad hash function is very small. 2. Randomized hashing a. Idea: pick a hash function at random, we’ll show that for any set of n items, the hash function is very likely to be good. (few collisions)
Background image of page 1

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

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

This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.

Page1 / 2

Cse101_10_10_11 - Hashing 1 Goal a Want to store n items a.i In O(n space a.ii With O(1 lookup time a.iii O(1 insertion/deletion time b Say the

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

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