Any help would be appreciated.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can intersect any two sorted lists in linear time.
This runs in O(n1+n2) and is optimal for the union operation (where you are bound by the output size).
Alternatively, you can look at all elements of the smaller tree to see if they are present in the larger tree. This runs in O(n1 log n2).
This is the algorithm Google uses (or considered using) in their BigTable engine to find an intersection:
To find an element or the next largest element in a binary tree iterator:
This decays to O(n1+n2) for similarly-sized sets that are perfectly mixed, and to O(n1 log n2) if the second tree is much bigger. If the range of a subtree in one tree does not intersect any node in the other tree / all other trees, then at most one element from this subtree is ever visited (its minimum). This is possibly the fastest algorithm available.