Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q25 — Binary Search Trees

Explain with AI
Suppose the values 10,−4,15,30,20,5,60,1910,-4,15,30,20,5,60,19 are inserted in that order into an initially empty binary search tree. Let TT be the resulting binary search tree. The number of edges in the path from the node containing 1919 to the root node of TT is _________. (Answer in integer)
View worked solution

Answer: 4:4

To find the number of edges in the path from the node containing 1919 to the root node, we construct the Binary Search Tree (BST) by inserting the elements one by one in the given order: 10,−4,15,30,20,5,60,1910, -4, 15, 30, 20, 5, 60, 19.

Step-by-Step Insertion:

  1. Insert 1010: Root of the tree.
        10
        
  2. Insert −4-4: Since −4<10-4 < 10, insert as the left child of 1010.
          10
         /
       -4
        
  3. Insert 1515: Since 15>1015 > 10, insert as the right child of 1010.
          10
         /  \
       -4    15
        
  4. Insert 3030: 30>10→30>1530 > 10 \rightarrow 30 > 15, insert as the right child of 1515.
          10
         /  \
       -4    15
               \
                30
        
  5. Insert 2020: 20>10→20>15→20<3020 > 10 \rightarrow 20 > 15 \rightarrow 20 < 30, insert as the left child of 3030.
          10
         /  \
       -4    15
               \
                30
               /
             20
        
  6. Insert 55: 5<10→5>−45 < 10 \rightarrow 5 > -4, insert as the right child of −4-4.
           10
          /  \
        -4    15
          \     \
           5     30
                /
              20
        
  7. Insert 6060: 60>10→60>15→60>3060 > 10 \rightarrow 60 > 15 \rightarrow 60 > 30, insert as the right child of 3030.
           10
          /  \
        -4    15
          \     \
           5     30
                /  \
              20    60
        
  8. Insert 1919: 19>10→19>15→19<30→19<2019 > 10 \rightarrow 19 > 15 \rightarrow 19 < 30 \rightarrow 19 < 20, insert as the left child of 2020.
           10
          /  \
        -4    15
          \     \
           5     30
                /  \
              20    60
             /
            19
        

Path from 1919 to the Root (1010):

The path from node 1919 to the root node 1010 is:

19→20→30→15→1019 \rightarrow 20 \rightarrow 30 \rightarrow 15 \rightarrow 10

The number of edges in this path is the number of transitions between nodes, which is:

5 nodes−1=4 edges5 \text{ nodes} - 1 = 4 \text{ edges}

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Search Trees questions