GATE | GATE MOCK 2017 | Question 46
Given two Balanced binary search trees, B1 having n elements and B2 having m elements, what is the time complexity of the best known algorithm to merge these trees to form another balanced binary tree containing m+n elements ?
(A) O(m+n)
(B) O(mlogn)
(C) O(nlogm)
(D) O(m2 + n2)
Answer: (A)
Explanation:
O(m+n) as we can first perform inorder on both the trees and store them in two separate arrays. Now we have two sorted sequences and we can merge them in O(m+n) using standard merge algorithm and on the final sorted array we can use the binary search to create the tree using Recursion. Recursively adding middle element at the root and repeating the same process for left and right subarrays.
Quiz of this Question
Recommended Posts:
- GATE | GATE 2017 MOCK II | Question 12
- GATE | GATE MOCK 2017 | Question 61
- GATE | GATE MOCK 2017 | Question 60
- GATE | GATE 2017 MOCK II | Question 39
- GATE | GATE 2017 Mock | Question 65
- GATE | GATE MOCK 2017 | Question 58
- GATE | GATE MOCK 2017 | Question 57
- GATE | GATE MOCK 2017 | Question 56
- GATE | GATE MOCK 2017 | Question 55
- GATE | GATE MOCK 2017 | Question 54
- GATE | GATE MOCK 2017 | Question 53
- GATE | GATE MOCK 2017 | Question 52
- GATE | GATE MOCK 2017 | Question 51
- GATE | GATE MOCK 2017 | Question 62
- GATE | GATE 2017 Mock | Question 63



