Hash 2 - CSC2100A Tutorial Hashing (Part 2) Spring...

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

View Full Document Right Arrow Icon
1 CSC2100A Spring 2006-2007 CSC2100A Tutorial Hashing (Part ) Spring 2006/2007 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CSC2100A Spring 2006-2007 Hashing II • Collision resolution – Separate Chaining (In previous tutorial…) – Open addressing • Linear probing • Quadratic probing •Random prob ing •Doub le hash • Rehashing • Extendible hashing
Background image of page 2
3 CSC2100A Spring 2006-2007 Hashing - Open addressing struct HashEntry { HashedObj element; EntryType info; /* ACTIVE = 0, EMPTY = 1, DELETED = 2 */ HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY ) : element( e ), info( i ) { } }; vector<HashEntry> array; /* The hash function */ intHash( intinput ,inttab leS ize){ return input % tableSize; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 CSC2100A Spring 2006-2007 Hashing - Open addressing • Open addressing – if collision occurs, alternative cells are tried. –h 0 (X), h 1 (X), h 2 (X), . .. h i (X) = (Hash(X) + F(i) ) mod TableSize – Linear probing : F(i) = i – Quadratic probing : F(i) = i 2 – Double hashing : F(i) = i * Hash 2 (X)
Background image of page 4
5 CSC2100A Spring 2006-2007 Hashing - Open addressing • Linear probing –F ( i ) = i h i (X) = (Hash(X) + i ) mod TableSize h 0 (X) = (Hash(X) + 0) mod TableSize, h 1 (X) = (Hash(X) + 1) mod TableSize, h 2 (X) = (Hash(X) + 2) mod TableSize, . ..
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the 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 / 25

Hash 2 - CSC2100A Tutorial Hashing (Part 2) Spring...

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

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