{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture16-2

Lecture16-2 - Lecture 16 Hash Tables Motivation Behind Hash...

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

View Full Document Right Arrow Icon
Lecture 16: Hash Tables
Background image of page 1

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

View Full Document Right Arrow Icon
Motivation Behind Hash Tables Would like a data structure which allows you to do find, insert, and delete very fast First Attempt: Direct Addressing Suppose the data structure will store integer keys in the range 0 to 99,999 Use an array of size 100,000 Store key k in position k (array positions not containing a key will contain some special value) Can do find, insert, delete in constant time DRAWBACK: Too much wasted space! (if number of keys is much less than size of range)
Background image of page 2
Hash Tables Modify previous idea. Idea: Don’t store key k in position k, but in position h(k). h(k) is hash function, takes key as input and produces an index into the array Problem: Collisions! Distinct keys k1 and k2 may have same hash value, i.e. h(k1) = h(k2) Can’t store both k1 and k2 in same array entry
Background image of page 3

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

View Full Document Right Arrow Icon
Different kinds of hash tables Hash table implementations differ in Choice of hash function Method of resolving collisions
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

Lecture16-2 - Lecture 16 Hash Tables Motivation Behind Hash...

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

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