crazyfundu
BAN USERI dont think there is any other better approach.
- crazyfundu July 04, 2012This logic and two problems as compared to MinHeap
1. More memory usage
2. Worst Case complexity higher
While iterating slow and false pointers, they will meet at a place and we'll know that loop is there as explained above. Freeze one pointer there and and again make the other pointer to point at the head. Now iterate both pointers one-one step. They will meet again and that will be the starting point. No need to find the length of the the loop !!!
- crazyfundu July 03, 2012I think this approach would only compare the structure. But what about values?
3,1,6 & 3,2,7 both will give you same value!!!
We might create a list of buckets like trie data structure (The number and type of buckets depends on the 'content of User IDs'). We read one file and fill those buckets. We keep BST maintained under each bucket as said by shondik in above comment,
Now we keep reading the second file and check for an ID in particular bucket.
In this way we can reduce the searching as compared to pure BST!!!
yes. That's a better solution. :)
- crazyfundu July 05, 2012