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

Category: QuestionsTwo balanced binary trees are given with m and n elements respectively. They can be merged into a balanced binary search tree in ____ time.
Editor">Editor Staff asked 5 months ago

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 I

The question was posed to me in a job interview.

Editor">Editor Staff answered 5 months ago

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.

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17

Notice: Trying to get property 'ID' of non-object in /home/fvckxqmi/public_html/wp-content/themes/blocksy/inc/single/single-helpers.php on line 17
Articles: 40702