PadhaikoAll subjects

Past exam question: 2065 Shrawan (Regular / Back), Q5(b)

Data Structure and Algorithms · 4 marks

Open in the Padhaiko app

Topic: Balanced binary tree · Introduction to red-black tree · B-Tree: Need…

Question

Create AVL tree using following data sets. 14, 12, 20, 18, 23, 4, 44, 64, 66 Show all the steps including rotation where ever needed clearly.

Solution

Insert 14, 12, 20, 18, 23, 4, 44:

Insert 64 (RR Rotation at 23) and 66 (RR Rotation at 20):

                 14 (-1)
               /         \
           12 (+1)       44 (0)
           /            /      \
         4 (0)       20 (0)    64 (-1)
                     /    \        \
                  18 (0)  23 (0)   66 (0)
Answer:

Final AVL tree has root 14, left subtree 12 (left 4), and right subtree 44 (left 20 with children 18, 23; right 64 with right 66).

All past exam questions for Data Structure and Algorithms