Hash - Algorithm Notes

Hash

Cited Example: N = {8,3,7,6,2}, {7,4,2} = M, Q that each number of the number M N of whether there had been in. M, N is the most intuitive idea is to traverse, the time complexity of O (MN), when M and N are great when it is unbearable.

Solution: space for time, define a bool array hashTable [100010], wherein hashTable [x] == true x represents a positive integer N appeared in positive integers. This can be pretreated to start reading a positive integer N times.

This direct input of the number of data in the array as the target mode is good, but it can handle is limited, then a large number if the digital or input string, such as the subject of direct mode can not be used under the array a.

Solution: by a function (hash function), the input element to an integer, that integer may be such that only representative of this element.

Not started, in general, you can use the map directly using a hash function, C ++ can be used after 11 unordered_map. faster.

 

String hash: to 0-25 as AZ, az as the 26-51, accordingly called on the conversion issue fifty binary and decimal conversion.

 

 

Published 98 original articles · won praise 2 · Views 3700

Guess you like

Origin blog.csdn.net/qq_30377869/article/details/105024758