GateAI
Binary Search Trees

GATE CSE 2025 Set 2 · Q35

NAT1 markEasy

Time

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 19 to the root node of TT is ________ . (Answer in integer)

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 4

Binary Search Trees

Let us trace the insertions into the binary search tree (BST):

  1. Insert 10: Root of the tree.

  2. Insert -4: Since −4<10-4 < 10, it becomes the left child of 10.

  3. Insert 15: Since 15>1015 > 10, it becomes the right child of 10.

  4. Insert 30: 30>10  ⟹  30 > 10 \implies right of 10; 30>15  ⟹  30 > 15 \implies right child of 15.

  5. Insert 20: 20>10  ⟹  20 > 10 \implies right of 10; 20>15  ⟹  20 > 15 \implies right of 15; 20<30  ⟹  20 < 30 \implies left child of 30.

  6. Insert 5: 5<10  ⟹  5 < 10 \implies left of 10; 5>−4  ⟹  5 > -4 \implies right child of -4.

  7. Insert 60: 60>10  ⟹  60>15  ⟹  60>30  ⟹  60 > 10 \implies 60 > 15 \implies 60 > 30 \implies right child of 30.

  8. Insert 19: 19>10  ⟹  19>15  ⟹  19<30  ⟹  19<20  ⟹  19 > 10 \implies 19 > 15 \implies 19 < 30 \implies 19 < 20 \implies left child of 20.

The path from the root node (10) to the node containing 19 is:

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

The edges on this path are:

  1. (10,15)(10, 15)

  2. (15,30)(15, 30)

  3. (30,20)(30, 20)

  4. (20,19)(20, 19)

Therefore, the number of edges is 4.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Binary Search Trees previous year question is Q35 of the GATE CSE 2025 Set 2 paper. Find more GATE CSE PYQs on Binary Search Trees in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Search Trees PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Search Trees in GATE CSE

Binary Search Trees has 21 GATE CSE PYQs across 17 papers from 2011 to 2026. 2 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2025 Set 2.

How GATE tests Binary Search Trees

More from GATE CSE 2025 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 2 · Q35 · NAT

Suppose the values 10, -4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let T be the resulting binary search tree. The number of edges in the path from the node containing 19 to the root node of T is … (Answer in integer)

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.