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
- A data structure is required for storing a set of integers such that each of the following O(log n) operations can be done in time, where n…
- Consider the following graph. Among the following sequences I. a b e g h f II. a b f e h g III. a b f h g e IV. a f g h b e Which are depth…
- Which of the given options provides the increasing order of asymptotic complexity of f1, f2, f3 f4 functions and ? f1(n) = 2n A. f2(n) = n3…
- A hash function h(key) = key mod 7 with linear probing is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed 0 to 6. W…
- Match each graph algorithm with its time complexity (n vertices, m edges). List I: A. Bellman-Ford, B. Kruskal's algorithm, C. Floyd-Warsha…
- The reverse Polish notation of the infix expression [A * {B + C * (D + E)}] / {F * (G + H)} is