Code Regarding Binary Tree | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code Regarding Binary Tree

Once Monk was watching a fight between an array and a tree, of being better. Tree got frustrated and converted that array into a Binary Search Tree by inserting the elements as nodes in BST, processing elements in the given order in the array. Now Monk wants to know the height of the created Binary Search Tree. (2 Marks) Help Monk for the same. Input Format : The first line will consist of 1 integer N, denoting the number of elements in the array. In next line, there will be N space separated integers, A[i] where 1 ≤ i ≤ N, denoting the elements of array. Output Format Print the height of the created Binary Search Tree. Constraints: : 1 ≤ N ≤ 103 1 ≤ A[i] ≤ 106 Sample Input Sample Output 4. 3 2 1 3 4 Explanation:- N = 4. Insert 2. It becomes root of the tree. Insert 1. It becomes left child of 2 Insert 3. It becomes right child of 2 Insert 4. It becomes right child of 3. Final height of tree = 3.

6th Apr 2020, 4:29 AM
Datta Bezawada
Datta Bezawada - avatar
1 Answer
0
Datta Bezawada Please show your attempts👍
4th Mar 2021, 9:27 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar