InterviewSolution
Saved Bookmarks
| 1. |
Two balanced binary trees are given with m and n elements respectively. They can be merged into a balanced binary search tree in ____ time.(a) O(m+n)(b) O(mn)(c) O(m)(d) O(mlog n)My question is taken from Binary Trees topic in chapter Binary Trees of Data Structures & Algorithms IThe question was posed to me in a job interview. |
|
Answer» CORRECT option is (a) O(m+n) To explain: FIRST we STORE the in-order traversals of both the trees in two separate arrays and then we can merge these sorted sequences in O(m+n) TIME. And then we construct the balanced tree from this final sorted array. |
|