Given an array that stores a complete Binary Search Tree, write a function that efficiently prints the given array in ascending order.
For example, given an array [4, 2, 5, 1, 3], the function should print 1, 2, 3, 4, 5
Inorder traversal of BST prints it in ascending order. The only trick is to modify recursion termination condition in standard Inorder Tree Traversal.
1 2 3 4 5
Time Complexity: O(n)
Please write comments if you find the above solution incorrect, or find better ways to solve the same problem.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find k-th smallest element in BST (Order Statistics in BST)
- Flatten BST to sorted list | Decreasing order
- Flatten BST to sorted list | Increasing order
- How to check if a given array represents a Binary Heap?
- Two nodes of a BST are swapped, correct the BST
- K'th Largest Element in BST when modification to BST is not allowed
- Convert a normal BST to Balanced BST
- Two nodes of a BST are swapped, correct the BST | Set-2
- Check if an array represents Inorder of Binary Search tree or not
- Sorted Array to Balanced BST
- Construct BST from its given level order traversal
- Sorted Linked List to Balanced BST
- Check given array of size n can represent BST of n levels or not
- Count permutations of given array that generates the same Binary Search Tree (BST)
- Print nodes of a Binary Search Tree in Top Level Order and Reversed Bottom Level Order alternately
- Find the largest BST subtree in a given Binary Tree | Set 1
- Print BST keys in the given range
- Construct BST from given preorder traversal | Set 1
- Construct BST from given preorder traversal | Set 2
- Find a pair with given sum in a Balanced BST