1 1 vote In an AVL tree a single insertion can cause how many rotations at a particular time in worst case? Programming in C + – anjali007 1.2k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 1 1 vote In worst case there will be only 2 rotation. In best case 0 rotation. Ashish Mishra 9 answered Nov 21, 2018 • selected Dec 1, 2018 by anjali007 Ashish Mishra 9 comment Share Follow See all 9 Comments 9 9 Comments reply anjali007 commented Nov 21, 2018 reply Follow flag can u pls explain why ?? 0 0 replyShare Ashish Mishra 9 commented Nov 21, 2018 reply Follow flag if after insertion avl tree is not disturbed then 0 rotation required. But if after insertion it is not balanced then it can create either LL or RR or LR or RL problem. If it ll or rr then only one rotation is required. But if it is lr or rl then 2 rotation is required. Since we need to convert them to either ll or rr depending on the problem. and we can also show that height of the node is not disturbed hence in backtracking there will be no problem. 0 0 replyShare anjali007 commented Nov 22, 2018 reply Follow flag ok got it .. thanks !! 0 0 replyShare Deepanshu commented Nov 22, 2018 reply Follow flag asking about tree not single node first of all.... so it should be depend on height .. because if our avl tree has some height then only not leaf node going to suffer from rotation but we may change also root due to rotation .... 0 0 replyShare Deepanshu commented Nov 22, 2018 reply Follow flag 2 is never going to be answer 0 0 replyShare anjali007 commented Nov 22, 2018 reply Follow flag @Deepanshu I also thought the same thing.. but they have given the ans as 2... 0 0 replyShare Deepanshu commented Nov 22, 2018 reply Follow flag then may be they mistake in question of node and tree because with tree if answer is 2 then it is not making much sense ... 0 0 replyShare anjali007 commented Nov 22, 2018 reply Follow flag then what should be the ans for tree? 0 0 replyShare Deepanshu commented Nov 22, 2018 reply Follow flag may be 2 is the right answer ....nice question.. as previous all subtree are all already balanced so for that tree it is going to affect they are gonna do and at a time i am only getting 1 tree which is out of place so i think maybe 2 but no valid proof just examples from here and there 0 0 replyShare Please log in or register to add a comment.