RTUComputer ScienceYr 2023 · Sem 32023

Q20Data Structures

Question

10 marks

Create an AVL tree using the following nodes 10, 6, 11, 12, 1, 7, 0, 2, 3. What will be the resulting AVL tree if node 12 is deleted from above AVL tree?

Answer

A detailed trace executing the complex insertion and rotation sequence to build an AVL tree from a dataset, followed by the rigorous rebalancing protocol required after targeted node deletion.

An AVL tree fiercely maintains its operational efficiency by continuously enforcing a strict structural constraint: the absolute mathematical difference in height (Balance Factor) between any given node's left and right subtrees must never exceed 1. We must meticulously trace the construction of the tree with the sequence 10, 6, 11, 12, 1, 7, 0, 2, 3, applying structural rotations whenever this critical tolerance is violated.

Part A: Step-by-Step AVL Tree Construction Trace

  • Insert 10: Root established. Tree is perfectly balanced.
  • Insert 6: Placed as left child of 10. Tree is balanced (BF of 10 is +1).
  • Insert 11: Placed as right child of 10. Tree is perfectly balanced (BF of 10 is 0).
  • Insert 12: Placed as right child of 11. Tree is balanced (BF of 10 is -1, BF of 11 is -1).
  • Insert 1: Placed as left child of 6. Tree is balanced (BF of 10 is +1, BF of 6 is +1).
  • Insert 7: Placed as right child of 6. Tree is perfectly balanced (BF of 6 is 0, BF of 10 is 0).
  • Insert 0: Placed as left child of 1. CRITICAL IMBALANCE: Node 6 now possesses a Left-Left heavy imbalance (). Correction: Execute an immediate Right Rotation (LL case) aggressively pivoting entirely around Node 6. Node 1 physically elevates to replace 6. Node 0 remains left child of 1. Node 6 violently drops to become the right child of 1. Node 7 remains right child of 6.
  • Insert 2: Placed as right child of 0. CRITICAL IMBALANCE: Node 10 (the Root) now detects a severe Left-Left heavy imbalance (). Correction: Execute a massive Right Rotation (LL case) pivoting completely around the primary Root 10. Node 1 fiercely elevates to become the absolute new Root of the entire tree. Node 10 mathematically drops to become the right child of 1. The previous right child of 1 (which was the entire subtree rooted at 6) mathematically transfers to become the new left child of 10.
  • Insert 3: Placed as right child of 2. CRITICAL IMBALANCE: Node 0 detects a Left-Right heavy imbalance (). Correction: Execute a complex two-step Left-Right (LR) Rotation. First, Left rotate pivoting on 2. Node 3 elevates, 2 drops. Second, Right rotate pivoting on 0. Node 3 violently elevates again to replace 0.

Final Top-Level Architectural Structure after complete insertion: - Absolute Root: 1 - Root's Left Child: 3 (with Left Child 0, Right Child 2) - Root's Right Child: 10 (with Left Child 6 [Left empty, Right 7], and Right Child 11 [Right 12]).

Part B: The Deletion Protocol

The algorithm now mandates the deletion of target node 12. Step 1 (Physical Deletion): Locate node 12. As a terminal leaf node (child of 11), it is trivially severed and its memory freed without requiring complex structural replacement protocols.

Step 2 (Ascending Rebalance Check): Following deletion, the algorithm must re-traverse the path upward back to the root, exhaustively recalculating the Balance Factor of every node along the ascending trajectory.

  • Check Node 11: Left subtree height = 0, Right subtree height = 0. . Balanced.
  • Check Node 10: Left subtree (rooted at 6) height = 2. Right subtree (rooted at 11) height = 1. . Balanced.
  • Check Root 1: Left subtree (rooted at 3) height = 2. Right subtree (rooted at 10) height = 3. . Balanced.

The post-deletion structural verification process mathematically confirms that the violent removal of node 12 did not perturb the overarching tree architecture beyond allowable limits. No further corrective algorithmic rotations are necessary. The AVL tree retains its strict integrity.

Back to Paper