Question
In the following, B1 and B2 are two binary search trees such that every key in B1 is smaller than every key in B2. Describe
In the following, B1 and B2 are two binary search trees such that every key in B1 is smaller than every key in B2. Describe an algorithm that, given pointers b1 and b2 to the roots of B1 and B2, merges B1 and B2 into a single binary search tree T. Your algorithm should satisfy the following two properties: 1. Its worstcase running time is O(min{h1, h2}), where h1 and h2 are the heights of B1 and B2. 2. The height of the merged tree T is at most max{h1, h2} + 1. Note that the heights h1 and h2 are not given to the algorithm (in other words, the algorithm does not know the heights of B1 and B2). Note also that B1, B2 and T are not required to be balanced. Describe your algorithm, and justify its correctness and worst-case running time, in clear and concise English. Note: Partial credit may be given for an algorithm that runs in O(max{h1, h2}) time.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started