首页 > 其他 > 详细

HashMap Collision Resolution

时间:2015-11-10 06:59:14      阅读:294      评论:0      收藏:0      [点我收藏+]

Separate Chaining

Use data structure (such as linked list) to store multiple items that hash to the same slot

1. use linked list
Collision: insert item into linked list
Find: compute hash value, then do Find on linked list

2. use BST
O(log N) time instead of O(N). But lists are usually small - not worth the overhead of BSTs

Open addressing (or probing)

Search for other slots using a second function and store items in first empty slot that is found

Separate chaining can take up a lot of space...

Given an item X, try cells h0(X), h1(X), h2(X), .., hi(X)
hi(X) = (Hash(X) + F(i)) mod TableSize
(Define F(0) = 0)

Linear: F(i) = i
Quadratic: F(i) = i2
Double Hashing: F(i) = i * Hash2(X)

details

 

HashMap Collision Resolution

原文:http://www.cnblogs.com/ireneyanglan/p/4951765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!