Uniform hashing functions

拜拜、爱过 提交于 2019-12-12 03:28:51

问题


Hash table basics: - MAJOR TEST COMING UP. ALL HELP WOULD BE APPRECIATED.

I am basically a bit confused on uniform hashing of keys.

----------------------
| X X X                    <=== Chains; X represents an item in there
----------------------
| X X X                    <=== Multiple X represents collisions
---------------------- 
| 
----------------------
| X X X
----------------------
| X
----------------------
  1. Consider the case of the above hash table where M = 5 (num of rows) and the total length to be 10. How would I know if this is hash table is uniformly hashed or not?

  2. If one makes a uniform hashing of a set of keys, does that mean the lists inside the chains in a hashtable aka the linked-lists due to collisions have the same length? Or does it mean the average?

  3. If one makes a uniform hashing of keys, does that mean the find and remove functions of this hashtable are O(1) (amortized) and a pure complexity of O(n/M) where M is the number of chains in total?

  4. Does the load factor or (N/#ofChains) identify the uniformity of the hashing?

I hope you can help me with these questions. My professor had put a lot of concepts out in class and I am just basically bending them together here and I am getting confused when I put these concepts together.

I was searching on the web for more to study about this concept and I saw a set of slides as shown below. I would be obliged if you can explain to me what the equation means in the second slide in relation to uniform hashing of keys.

Also, what does it mean when they say "the number of keys that map to each slot are equal." Does go to say that my hashtable that is shown above is NOT uniformily hashed?

Thank you


回答1:


The slide is talking about all possible values of keys. It's important to realize that in your hashmap, you only have a subset of keys at any given time. Regardless of how good your hash function is, you might be lucky in how those keys map to buckets, or you might be not.

1) Consider the case of the above hash table where M = 5 (num of rows) and the total length to be 10. How would I know if this is hash table is uniformly hashed or not?

Uniform hashing is a property of the hash function, not of the hash table. Therefore, just by looking at the contents of the hash table, you can't. You have to look at the hash function itself to establish whether or not it's uniform.

2) If one makes a uniform hashing of a set of keys, does that mean the lists inside the chains in a hashtable aka the linked-lists due to collisions have the same length? Or does it mean the average.

It means on average.

3) If one makes a uniform hashing of keys, does that mean the find and remove functions of this hashtable are O(1) (amortized) and a pure complexity of O(n/M) where M is the number of chains in total.

In addition to the properties of the hash function, complexity also depends on the load factor. If the number of buckets grows linearly in the number of elements, you get O(1) find and remove on average (as long as you amortize re-bucketing appropriately).



来源:https://stackoverflow.com/questions/13838178/uniform-hashing-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!