Reputation: 1
Give a randomized expected linear-time algorithm using ideal hash functions that determines whether two arrays A[1..n] and B[1..n] are disjoint, i.e., whether no element of A is also an element of B.
Can anyone show me how to do this or even how to start thinking about it?
Upvotes: 0
Views: 237
Reputation: 33740
for element in a:
hasha{element} = 1
for element in b:
if hasha{element} == 1:
print element "found in both"
Time: O(len(a)+len(b))
Upvotes: 3