182777/insertion-in-avl["182777","insertion-in-avl"]Array ( [account] => pages/account.php [activity/] => pages/activity.php [admin/] => pages/admin/admin-default.php [admin/approve] => pages/admin/admin-approve.php [admin/categories] => pages/admin/admin-categories.php [admin/flagged] => pages/admin/admin-flagged.php [admin/hidden] => pages/admin/admin-hidden.php [admin/layoutwidgets] => pages/admin/admin-widgets.php [admin/moderate] => pages/admin/admin-moderate.php [admin/pages] => pages/admin/admin-pages.php [admin/plugins] => pages/admin/admin-plugins.php [admin/points] => pages/admin/admin-points.php [admin/recalc] => pages/admin/admin-recalc.php [admin/stats] => pages/admin/admin-stats.php [admin/userfields] => pages/admin/admin-userfields.php [admin/usertitles] => pages/admin/admin-usertitles.php [answers/] => pages/answers.php [ask] => pages/ask.php [categories/] => pages/categories.php [comments/] => pages/comments.php [confirm] => pages/confirm.php [favorites] => pages/favorites.php [favorites/questions] => pages/favorites-list.php [favorites/users] => pages/favorites-list.php [favorites/tags] => pages/favorites-list.php [feedback] => pages/feedback.php [forgot] => pages/forgot.php [hot/] => pages/hot.php [ip/] => pages/ip.php [login] => pages/login.php [logout] => pages/logout.php [messages/] => pages/messages.php [message/] => pages/message.php [questions/] => pages/questions.php [register] => pages/register.php [reset] => pages/reset.php [search] => pages/search.php [tag/] => pages/tag.php [tags] => pages/tags.php [unanswered/] => pages/unanswered.php [unsubscribe] => pages/unsubscribe.php [updates] => pages/updates.php [user/] => pages/user.php [users] => pages/users.php [users/blocked] => pages/users-blocked.php [users/new] => pages/users-newest.php [users/special] => pages/users-special.php [admin/donut-theme/] => ../qa-plugin/Donut-admin/admin/admin-panel.php [admin/donut-theme/general-settings] => ../qa-plugin/Donut-admin/admin/admin-panel.php [exams/] => ../qa-plugin/exam-creator/pages/exams.php [user-exams] => ../qa-plugin/exam-creator/pages/exam-user-taken-page.php [admin/exam/] => ../qa-plugin/exam-creator/admin/exam-admin-options.php [admin/exam/categories] => ../qa-plugin/exam-creator/admin/exam-admin-categories.php [admin/exam/hidden] => ../qa-plugin/exam-creator/admin/exam-admin-hidden.php [admin/exam/moderate] => ../qa-plugin/exam-creator/admin/exam-admin-moderate.php [admin/exam/recalc] => ../qa-plugin/exam-creator/admin/exam-admin-recalc.php [admin/exam/stats] => ../qa-plugin/exam-creator/admin/exam-admin-stats.php )
Deprecated: Implicit conversion from float-string "1581230439.151" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1581230439.151" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1581230439.151" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1581230439.151" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1581230439.151" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1581239061.032" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1581239061.032" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1581239061.032" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1581239061.032" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1581239061.032" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1619419967.591" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1619419967.591" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1619419967.591" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1619419967.591" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1619419967.591" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1544451613.004" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1544451613.004" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1544451613.004" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1544451613.004" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1544451613.004" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
INSERTION IN AVL / GATE Overflow for GATE CSE
retagged by
2,036 views
5 votes
5 votes

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 answer if it asked that element is continuously inserting in to a AVL tree.

retagged by

1 Answer

0 votes
0 votes

So, if we have n nodes in the AVL tree and we add one more number it will take O(logn) time to insert it. AVL trees balanced binary tree so at any point of time AVL tree will have a height of O(h) (where h=logn).

When we insert any node to the AVL tree following are the steps to be taken.

1. Find the appropriate place of insertion .(i.e do a binary search to get the location to insert element, as it is already sorted it will take O(logn) time.

2. Updating the height (it takes constant time )

3. Rotations  (it also takes constant time, as we have to just update some pointers)

 

Now, if we want to add m more nodes to the tree it will take another m insertions and time complexity for each insertion would be:- 

  $log(n+1) + log(n+2)+ log(n+3)+ .....+log(n+m)$ 

 =$log((n+1)*(n+2)*(n+3)*....* (n+m-1)*(n+m))$

=$log ( (n+m)! /(n!))$

=$(n+m) log(n+m)- nlogn$

=$O((n+m) log (n+m))$

edited by

Related questions


Deprecated: Implicit conversion from float-string "1665300314.722" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1665300314.722" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1665300314.722" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1665300314.722" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
3.8k
views
4 answers
1 votes
GateAspirant999 asked Apr 23, 2016
3,777 views
The tree given is as follows: 40 / \ 35 53 / \ 20 60 How many rotations are required for insertion of elements 30,55,45,6...
5.8k
views
4 answers
5 votes
srestha asked Jan 16, 2017
5,807 views
What is the worst case time complexity to construct an AVL tree from an array which satisfies the min heap property ?a) O(n log n)b) O(n2)c) O(n2 log n)d) O(n)
398
views
0 answers
1 votes
Chaitanya Kale asked Oct 9, 2022
398 views
Given a skew tree what will be the time complexity to balance the tree? What will be the algorithm for this?
748
views
1 answers
0 votes
Arnabi asked Jan 28, 2017
748 views
Total PHP MySQL Other RAM
Time (ms) % Time (ms) % File count Time (ms) % Query count Time (ms) % Amount %
Setup 5.6 9% 4.1 6% 72 1.8 3% 2 0.0 0% 569k 49%
Control 15.1 25% 2.0 3% 5 13.6 22% 12 0.0 0% 237k 20%
View 3.2 5% 3.2 5% 12 0.0 0% 0 0.0 0% 72k 6%
Theme 27.6 46% 4.5 7% 15 23.3 38% 3 0.0 0% 280k 24%
Stats 8.2 13% 0.1 0% 0 8.1 13% 1 0.0 0% 0k 0%
Total 59.7 100% 13.8 23% 104 46.8 78% 18 0.0 0% 1160k 100%