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

# Find binary search second largest element

The recursive approach to find second largest element of binary tree or binary search tree. supposed following data [89, 79, 150, 56, 654, 43, 78, 437, 600] are inserted on binary search tree. Given example to find second largest element. Algorithm:

Case 1: When root left subtree and right subtree are exist. Then follow this approach.

In this algorithm visit all bst node using recursion. Initial both pointer ( *first and *second ) are pointed to root node. if node data value are greater. Then *second pointer= *first pointer and *first pointer=* current visited node. continue this process and find second largest element.

Case 2: Special when root left subtree or right subtree are not exist. then before proceed first case do some modification. Change first_big and second_big initial value to main() function.

Time complexity of this Algorithm O(n).

## Execution process to find second largest element

This demo try to visualize how to find second largest element of given binary search tree.

second Largest element of this given tree is . Recursive approach.

Click To Visualize Code

### Accepted Output

Given BST tree node is:

50, 70, 30, 90, 20, 10, 15, 60, 80

Result :

Second large element data is 

Given BST tree node is:

50, 70, 30, 90, 20, 50, 45, 320, 80

Result :

Second large element data is 

Below in C implementation of this problem

Output
```43 56 78 79 89 150 437 600 654
Second Big element is 600
Free BST node
```