recategorized by
968 views
1 votes
1 votes
Consider a function AVLConstruction(). Which takes an array n elements as input in Ascending order and produce output as AVL tree for given array. AVLConstruction() function selects the median of the array and put it as the Root element. Recursively build Left subtree from the left half of array and right half of the array. what will be the complexity of AVLConstruction()?

A) O(nlogn)

B) O(n2)

C) O(n3)

D) O(n)
recategorized by

1 Answer

2 votes
2 votes

According to the problem description ,

We need to find the median so we know if :

Time needed to find median  = O(n) using selection algorithm

Now for recursive parts we are considering the left and right subtrees and these are of almost same sizes.

Hence if T(n) is complexity of entire problem so for subproblems we need 2T(n/2) time..And O(n) for median finding as mentioned earlier..Hence recurrence relation for time T(n) will be :

           T(n) = 2T(n/2) + O(n) 

==>     T(n) = O(nlogn)    by Masters theorem

Hence correct answer is O(nlogn)

Related questions

0 votes
0 votes
2 answers
1
vijju532 asked Jun 28, 2018
471 views
how does AVL tree requires o(logn) for all the operation i.e search insert and deletewhile other tree (bst,binary) requires o(n) is it due to balancing factor that avl tr...
5 votes
5 votes
1 answer
2
junaid ahmad asked Dec 19, 2017
2,030 views
Which of the following is highest upper bound that represents the time complexity of inserting an object into AVL tree with n-nodes.It must be 0(logn) right.What would be...