retagged by
13,621 views
27 votes
27 votes

What is the worst case time complexity of inserting $n^{2}$ elements into an AVL-tree with $n$ elements initially?

  1. $\Theta (n^{4})$
  2. $\Theta (n^{2})$
  3. $\Theta (n^{2}\log n)$
  4. $\Theta (n^{3})$
retagged by

2 Answers

Best answer
41 votes
41 votes

Answer : C
Steps: For worst case (in worst case insertion will cause $\Omega(\log n)$ operations in an AVL tree where $n$ is the number of nodes present.

  • $1^{st}$ insertion time complexity $= \Theta(\log n)$
  • $2^{nd}$ insertion time complexity $= \Theta(\log(n+1))$
  • $\vdots$
  • ${n^2}^{th}$ insertion time complexity = $\Theta(\log(n+n^{2}-1))$

Total number of operations $= \Theta(\log n) +  \Theta(\log (n+1)) + \ldots +  \Theta(\log(n+n^{2}-1))$

$\qquad \qquad \qquad= \Theta\left( \log \left(n.(n+1).(n+2)\ldots (n+n^2-1) \right)\right)$
$\qquad \qquad \qquad = \Theta\left(\log n^{n^2}\right)$ $(\because $ the highest degree term in the $\log$ expression will be $n^{n^2}.$
$\qquad \qquad \qquad = \Theta\left(n^2 \log n\right).$

edited by
7 votes
7 votes
1st insertion worst case time complexity = O(log n)

2nd insertion worst case time complexity = O( log (n+1) )

and so on...

So worst case time complexity = O(log n) +  O( log (n+1) ) + .... +  O( log (n+$n^{2}$) )

= O(log n*(n+1)*(n+2)*...(n+$n^{2}$))

= O(log f(n))

Maximum degree term of f(n) would be $n^{n^{2}}$ as you can see n would be multiplied $n^{2}$ number of time for sure.

So O(log f(n)) = O( log $n^{n^{2}}$) = O($n^{2}$logn)

So option C is correct.
Answer:

Related questions

6 votes
6 votes
2 answers
1
go_editor asked Dec 19, 2016
2,094 views
Mark the balance factor of each node on the tree given in the below figure and state whether it is height-balanced.
2 votes
2 votes
1 answer
2
im.raj asked Jun 16, 2016
5,416 views
The worst case time complexity of AVL is tree is better in comparison to binary search tree forSearch and Insert OperationsSearch and Delete OperationsInsert and Delete O...