首页 > 解决方案 > 是否有满足以下条件的散列函数

问题描述

是否有满足以下条件的散列算法?

let "hash_funct" be a hashing function that takes two args, and returns a hash value. so all the following will be true

Hash1 = hash_funct(arg1, arg2) <=> hash_funct(Hash1, arg1) = hash_funct(Hash1, arg2) = Hash1;

谁能指出我这个算法?或者如果它不存在,任何人都可以与我合作发明它吗?

更多解释:

想象一个 setS={A,B,C,D}和上面的 Hashing 函数。

如果我们可以 make: Hash1 = hash_funct(A,B,C,D),那么我们可以X通过检查哈希结果来检查一个元素是否在集合中hash_funct(Hash1,X) == Hash1 ? belogns to the set : doesn't belong

使用此属性,我们检查集合中元素的存在性 O(1) 而不是 O(NlogN)

标签: c++algorithmmathhashcryptography

解决方案


我想最高公因数(Hcf)适合这里。设 a 和 b 是两个数,x 是它们的最大公因数。

hcf(a,b) = x.

这意味着a = x*mb = x*n。这显然意味着:

hcf(x,x*m) = hcf(x,x*n) = hcf(x*n,x*m) = x

推荐阅读