notes46 - / index.html / Sho Kazahaya / CS251 Notes -...

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

View Full Document Right Arrow Icon
// index.html // Sho Kazahaya // CS251 Notes - Feb12.14.16 (2007) /* If some parts of these notes don't make sense, ask your neighbor for a better copy. I have terrible handwriting, so I'm pretty sure that I've copied some sections incorrectly. Also, I forgot to mark in my notes where 2/16 ended and 2/19 began. I apologize if there's anything overlapping.*/ -------------------------------------------------- #~ February 12, 2007 ~# Hashing Wrap-Up HASHING We have seen so far that entries with the same key are stored in the same list. ___ |___| ----- ----- ----- |___+-|k1,d1|--|k2,d2|--|k3,d3|--| |___| ----- ----- ----- --- |___| - | | ~~~ fig.1 ( hash(k1) == hash(k2) == hash(k3) ) This is not the only way to handle collisions. Another way is to store the values in the hash array itself and use the hash number as the index of where the data has to be stored. _____ |k1,d1| |-----| |k3,d3| |-----| | | |-----| i |k2,d2| (i=k2) |-----| ~~~~~ fig.2 If a collision occurs:
Background image of page 1

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

View Full DocumentRight Arrow Icon
- Use the next available entry (also called linear probing ) - Use a second hash function to the amount of entries that have to be skipped ( double hashing ) LINEAR PROBING // Start pseudo code insert (k,d){ if table is full return error index = hash(k) while(entry at index is used) index = (index+1)%N store(k,d) in table[index] } // End pseudo code _____ | | |-----| |(d,x)| index = hash(k) |-----| | | |-----| | | ~~~~~ fig.3 Advantages of linear probing VS. hashing with linked lists ( chaining
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University.

Page1 / 9

notes46 - / index.html / Sho Kazahaya / CS251 Notes -...

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

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