Improvement Using Hashing
Idea:
• Don’t keep an array of bins
• Instead, place the occupied
bins in a hash table
• Hash on the bin’s array
indices
Result:
• Initialization takes time O(n)
instead of O(b)
• Still fast to test whether q
falls in an occupied bin
– A single test takes expected
time O(1) instead of worst-
case time O(1)
• Algorithm now runs in
expected time O(m2n)
instead of worst-case time
O(b+m2n)
CS409 - Spring 2000
9