All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · November 2021

Two balanced binary trees are given with m and n elements, respectively. They can be merged into a balanced binary search tree in ____ time.

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. O(m + n)

Explanation

Inorder-traverse both trees into sorted arrays (O(m + n)), merge them (O(m + n)), and build a balanced BST from the merged array (O(m + n)).

More Data Structures and Algorithms questions