For a tree with just one node, the root node, the height of a bin

For a tree with just one node, the root node, the height of a bin
|

For a tree with just one node, the root node, the height of a binary tree is defined to be zero; if there are 2 levels of nodes, the height is 1 and so on. Binary search tree is built according to the usual rules with the following six keys, inserted one at a time given:

B, I, N, A, R, Y. what is the height of the tree?  

A. 2

B. 4

C. 3

D. 5

Please scroll down to see the correct answer and solution guide.

Right Answer is: B

SOLUTION

Concept:

Binary search tree is a tree in which all the nodes in the left subtree of root are smaller than the root and nodes in the right subtree are greater or equal to the root node.

Explanation:

Given keys are :

B, I, N, A, R, Y 

Sorted keys:  A, B, I, N, R, Y

When these keys are inserted to form a binary search tree , tree will look like as : 

So, height of this binary search tree will be 4.

Algorithms:

A BST is a binary tree where nodes are ordered in the following way:

  • each node contains one key (also known as data)
  • the keys in the left subtree are less than the key in its parent node, in short L < P;
  • the keys in the right subtree are greater than the key in its parent node, in short P < R;