Question
In an AVL tree, what happens if a node insertion causes
the balance factor of a node to become +2 or -2?Solution
An AVL tree is a self-balancing binary search tree where the balance factor of each node (height difference between the left and right subtrees) is kept between -1 and +1. When the balance factor becomes +2 or -2 after an insertion, the tree violates this property and must be rebalanced using rotations. The type of rotation depends on the imbalance: • Single Rotation: Used when the imbalance is in one direction, either left-heavy (LL rotation) or right-heavy (RR rotation). • Double Rotation: Used when the imbalance involves opposite directions, such as left-right (LR rotation) or right-left (RL rotation). Option 2 is correct because the AVL tree algorithm always rebalances the tree after insertion using rotations to ensure logarithmic height. Why Other Options Are Incorrect: 1. Tree becomes unbalanced and cannot be used: Incorrect, as AVL trees are explicitly designed to handle imbalances. 2. Insertion is rejected: Incorrect, as rebalancing is performed instead of rejecting insertions. 3. Height increases by 2: Incorrect, as height adjustments depend on rebalancing and typically increase by at most 1. 4. Balance factor is ignored: Incorrect, as the balance factor is central to maintaining AVL tree properties.
Houses of six persons J, K, L, M, N and O are situated in two rows of three houses each sitting opposite to each other. M's house is diagonally opposite...
P, Q, R, S and T are five friends standing in a straight line facing towards north. P is on the immediate right of Q. T is between P and S. If R and Q a...
Who amongst the following is an immediate neighbour of the one who likes Black?
How many persons are sitting between P and X?
Eight friends Kriti, Durga, Manasi, Surya, Tahira, Vritti, Ahana and Yoshita are sitting around an square table in such a way that four friends are sitt...
How many persons are sitting around the circular table?
Seven friends A, B, C, D, E, F and G are sitting around a circular table facing towards the centre(not necessarily in the same order). A is third to the...
Eight persons M, N, O, P, Q, R, S and T sit around a circular table such that each of them faces towards the centre. S sits second to the right of T. O...
Eight birds P, Q, R, S, T, U, V and N are sitting in a row facing North."T' is fourth to the left of 'P'. 'S' is fourth to the right of 'N'. 'R' and 'U'...
The one who sits second to the right of Hitesh sells which of the following items?