Learn basic concept of c , c++ and python programming in regularcodes.com

# Finding height of a binary search tree without using recursion.

How to find Binary Search Tree height using iterative approach ? The two conventions of count height of BST.

1) By Node: (Number of Nodes having from Root node to longest (deepest) path leaf)

2) By Edge: (Number of Edge are connected having from Root node to longest(deepest) leaf).

View and Edit This Tree

Try it Yourself

## Height of BST by node

Following data are inserted BST tree [ 452, 401, 550, 429, 452, 593, 413, 521, 576, 428 ]

View and Edit This Tree Try it Yourself

### Longest Path:

From root to leaf is [452, 401, 429, 413, 428].

Height: Height of this Tree By node is 5.

## Height of BST by edge

Following data are inserted BST tree [ 582, 529, 600, 511, 565, 491, 511, 575, 442, 417, 443 ].

View and Edit This Tree Try it Yourself

### Longest Path:

From root to leaf is [582, 529, 511, 491, 442, 443].

Height: count BST height by edge in following formula. (Number of longest path from root to leaf -1). In this case (6-1)=5

C code implement to Get height of BST. Look at below to iterative approach.

### Othere Example:

In this example showing both approaches Height by Nodes and by Edges.

View and Edit This Tree

#### Result:

Height of BST by Nodes : 5

Height of BST by Edges : 4

## Code execution Process:

Code execution of above given tree.

See Execution Process

Visualize all execution steps Visualize Code

Output