Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision Resolution Neil Tang 02/18/2010

Similar presentations


Presentation on theme: "Collision Resolution Neil Tang 02/18/2010"— Presentation transcript:

1 Collision Resolution Neil Tang 02/18/2010
CS223 Advanced Data Structures and Algorithms

2 CS223 Advanced Data Structures and Algorithms
Class Overview Separate chaining Load factor Open addressing: linear probing, quadratic probing and double hashing Rehashing CS223 Advanced Data Structures and Algorithms

3 CS223 Advanced Data Structures and Algorithms
Separate Chaining hash(x) = x mod 10 CS223 Advanced Data Structures and Algorithms

4 CS223 Advanced Data Structures and Algorithms
Construct the Table CS223 Advanced Data Structures and Algorithms

5 CS223 Advanced Data Structures and Algorithms
Chaining Operations CS223 Advanced Data Structures and Algorithms

6 CS223 Advanced Data Structures and Algorithms
Load Factor Load factor  = N/M, where N is the number of elements and M is the table size. The average length of a list is . In an unsuccessful search, the number of elements to examine is  on average. A successful search requires (1+ /2) links to be traversed on average. CS223 Advanced Data Structures and Algorithms

7 CS223 Advanced Data Structures and Algorithms
Open Addressing When collision, try alternative cells until an empty cell is found. hi(x) = (hash(x) + f(i)) mod TableSize, with f(0)=0 CS223 Advanced Data Structures and Algorithms

8 CS223 Advanced Data Structures and Algorithms
Linear Probing f(i) = i CS223 Advanced Data Structures and Algorithms

9 CS223 Advanced Data Structures and Algorithms
Linear Probing Even if the table is relatively empty, blocks of occupied cells may start forming. This effect is referred as primary clustering. The expected probing for insertion and an unsuccessful search is 1/2(1+1/(1-)2) and for a successful search is 1/2(1+1/(1- )). CS223 Advanced Data Structures and Algorithms

10 CS223 Advanced Data Structures and Algorithms
Quadratic Probing f(i) = i2 CS223 Advanced Data Structures and Algorithms

11 CS223 Advanced Data Structures and Algorithms
Quadratic Probing CS223 Advanced Data Structures and Algorithms

12 CS223 Advanced Data Structures and Algorithms
Quadratic Probing CS223 Advanced Data Structures and Algorithms

13 CS223 Advanced Data Structures and Algorithms
Quadratic Probing Theorem: If quadratic probing is used, and the table size is prime, then a new element can always be inserted if the table is at least half empty. The secondary clustering problem: elements that hash to the same position will probe the same alternative cells. CS223 Advanced Data Structures and Algorithms

14 CS223 Advanced Data Structures and Algorithms
Double Hashing f(i,x) = i*hash2(x) hash2(x) = 7 – (x mod 7) If x=23, then… CS223 Advanced Data Structures and Algorithms

15 CS223 Advanced Data Structures and Algorithms
Rehashing Roughly double the table size. Re-insert the elements. CS223 Advanced Data Structures and Algorithms

16 CS223 Advanced Data Structures and Algorithms
Rehashing CS223 Advanced Data Structures and Algorithms


Download ppt "Collision Resolution Neil Tang 02/18/2010"

Similar presentations


Ads by Google