legend986
January 28th, 2008, 07:57 PM
I came across this question of finding the intersection of two unsorted arrays in the shortest time. I had two ideas, one was a brute force - this does it in O(n^2) if I'm not mistaken. The other was to create a has table of the smaller array and then use the second array to map into the hash to determine if the key exists. I want to find out the complexity of this method. Can someone please help me out?
First array: Size of m
Second Array: Size of n
I saw the answer was something like O(mlogm + nlogn) + O(m+n) but I want to know how it is derived.
Also, are there any other methods to find this out?
First array: Size of m
Second Array: Size of n
I saw the answer was something like O(mlogm + nlogn) + O(m+n) but I want to know how it is derived.
Also, are there any other methods to find this out?