• S
    SwaseekhGATE Preparation
General
  • Dashboard
  • Syllabus
  • Questions
  • Aptitude
  • Mock Tests
  • TCS NQT 2026
Account
  • Pricing
  • Contact
  1. GATE CS
  2. PYQs
  3. Programming and Data Structures

Mark the balance factor of each node on the tree given in the below figure and state whether it is height-balanced. The tree is as follows: a / \ b c / \ d e \ f (Node 'a' is the root; 'b' and 'c' are children of 'a'; 'd' and 'e' are children of 'b'; 'f' is the right child of 'e')

GATE 1988 · Programming and Data Structures · AVL Tree · medium

Answer: Balance factors: d=0, f=0, c=0, e=-1, b=-1, a=2. The tree is NOT height-balanced because node 'a' has a balance factor of magnitude 2.

  1. Compute heights of all nodes (bottom-up): Leaves: height(d) = 0, height(f) = 0, height(c) = 0. height(e) = 1 + max(height(null), height(f)) = 1 + max(-1, 0) = 1. height(b) = 1 + max(height(d), height(e)) = 1 + max(0, 1) = 2. height(a) = 1 + max(height(b), height(c)) = 1 + max(2, 0) = 3.
  2. Compute balance factors and check AVL property: bf(d) = -1 - (-1) = 0 (leaf) bf(f) = -1 - (-1) = 0 (leaf) bf(c) = -1 - (-1) = 0 (leaf) bf(e) = height(null) - height(f) = -1 - 0 = -1 [right child f exists, left is null] bf(b) = height(d) - height(e) = 0 - 1 = -1 bf(a) = height(b) - height(c) = 2 - 0 = 2 Node 'a' has balance factor = 2, which violates the AVL condition |bf| <= 1.