Timer is Running

Array to BST
Submissions: 28799   Accuracy:


  Difficulty: Easy   Marks: 2

Given a sorted array. Write a program that creates a Balanced Binary Search Tree using array elements. If there are N elements in array, then floor(n/2)'th element should be chosen as root and same should be followed recursively.

The first line of input contains an integer T, denoting the number of test cases. The first line of each test case is N(size of array). The second line of each test case contains N input A[].


Print the preorder traversal of constructed BST.

1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 10000


1 2 3 4 5 6 7

4 2 1 3 6 5 7

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.