For a tree with just one node, the root node is the height of a binary tree is…
2017
For a tree with just one node, the root node is the height of a binary tree is defined to zero; if there are 2 levels of nodes, the height is 1 and so on. A Binary Search Tree is built according to the usual rules with the following six keys inserted one at a time as given: B, I, N, A, R, Y. What is the height of the tree?
- A.
5
- B.
2
- C.
3
- D.
4
Attempted by 541 students.
Show answer & explanation
Correct answer: D

The insertion is done based on the standard Binary Search Tree (BST) property using the alphabetical order of the letters. Letters appearing earlier in the alphabet are considered smaller, while letters appearing later are considered larger. For example, A < B < I < N < R < Y.
Using the sequence B, I, N, A, R, Y:
B becomes the root.
I > B, so it is inserted to the right of B.
N > I > B, so it is inserted to the right of I.
A < B, so it is inserted to the left of B.
R > N > I > B, so it is inserted to the right of N.
Y > R > N > I > B, so it is inserted to the right of R.
Thus, the longest path is B → I → N → R → Y, which contains 4 edges. Therefore, the height of the BST is 4.