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.
A motor-cycle covers 125 km with a speed of 60 km/hr. find the speed of the motor-cycle for the next 125 km journey so that the average speed of the who...
A train is travelling at the rate of 54 km/hr. How many seconds it will take to cover a distance of 3/5 km?
A person travels from the hostel to the college at a speed of 10 kmph on the bicycle and reaches a 4.5-minute delay. If he runs a bike with a speed of 2...
Amrita traveled a certain distance, covering 50% of it at a speed of 15 km/h, then 40% of the remaining distance at 7.5 km/h, and the rest at 9 km/h. If...
If a bicycle can cover 65 km in 10 hours while a car can cover 90 km in 5 hours then find the average speed of car.
A man covered a distance of 240 km in 4 hours on a bike. How much distance will he cover on a bicycle in 8 hours if he rides the bicycle at one-tenth th...
A bike travels the same distance in 'h + 2.5' hours compared to a truck's 'h' hours from point 'P' to point 'Q'. Should the trip be completed in half by...
The speed of a bike increases by 5 km/hr after every 1 hour. If the distance travelled by the bike in 1st hour is 10 km, the find the total distance tra...
- The speeds of Pooja and Neha are in the ratio 7:5 respectively. Seema covers a distance of 720 km in 12 hours. If Neha's speed is 25% less than Seema’s s...
- A person completes a journey in 300 minutes by train at a speed of 60 km/h. What should be his speed by bus to cover the same distance in 7 hours?