Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If it is for dichotomy to generate an integer,then each character actually corresponding to a assiic

Such as
ac = 6163
bb = 6262
So even without hash hashing algorithm it will not repeat. Moreover, hash algorithm can not guarantee that no collision. That case, why use hash it??? Seek to understand the reasons.

THANKS
Posted
Updated 21-Oct-13 20:45pm
v2

It is an optimization to narrow down the search field. It works just the same as a normal dictionary in real life. Dictionary makers could add words to the book as they go without any order what so ever. This makes it hard to find words because you would need to do a linear search from front to back. Instead they did as it is done in all dictionaries, they alphabetically sorted the words and each letter in the alphabet got its own section. There is more than one word starting with an "S" for example, but you can skip all the words starting with anything other than an "S". You must admit that makes it a whole lot better. You then go from there. The same goes here. It is a bucket list that stored multiple values in the same bucket on collisions. But that doesn't matter because then only the bucket needs to be searched instead of an array of all the items. Hopefully my example makes it more clear.

Good luck!
 
Share this answer
 
v2
Comments
XKD_24 22-Oct-13 4:50am    
Thank you very much.
Hashing is used to distribute values across an "array of buckets", with each "bucket" containing a single entry. Hashing algorithms are (or should be) selected to give a good chance of distributing entries across the whole range of "buckets" and will vary according to teh number of such buckets available.

In your example with just two characters, it seems silly to hash the value at all - but if you don't then the number of buckets you need is enough to hold nearly all the possible entries: 64K. Which is silly, because it is very unlikely that you will generate that number of strings. If instead you use a primitive hash such as adding the two bytes together and taking the low eight bits of the result, then you can allocate just 256 buckets, saving a huge amount of memory.

There is a lot, lot more to hashing than this, and much too much to cover here, so I would suggest you start with Wiki: http://en.wikipedia.org/wiki/Hash_table[^] which provides a good overview.
 
Share this answer
 
Comments
XKD_24 22-Oct-13 4:53am    
THANKS
OriginalGriff 22-Oct-13 4:57am    
You're welcome!
Because of combinatorial explosion of your algorithm.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900