Question: Consider two binary search trees ( BSTs ) named T 1 and T 2 , rooted at Root 1 and Root 2 , respectively. Both

Consider two binary search trees (BSTs) named T1 and T2, rooted at Root1 and Root2, respectively. Both T1 and T2 are AVL (Adelson-Velsky-Landis) trees with M(>0) and N(>0) nodes, respectively. Every node of T1 and T2 has three fields: value, left-link and right-link. T1 and T2 have no common value. Define merging of a BST T2 with a BST T1 as a process that combines the two BSTs to form a single BST by attaching the root of T2 to a left- or right-link of T1 that is free. Thus, the merge operation excludes one by one insertion of the nodes of one BST into the other. (a) Create two AVL trees TA (with 6 integer values) and TB (with 7 integer values), such that TB cannot be merged with TA as per the above definition. Note that TA and TB must not have any common value. (b) Design an algorithm that takes two AVL trees T1 and T2 as input and merges T2 with T1, if possible, otherwise reports an error. Explain your algorithm. Deduce the time complexity of your algorithm, and also find the maximum possible height of the merged tree in terms of the heights of T1 and T2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!