BSTINORDER - Editorial

Prerequisites :- Binary Search Trees, Binary Tree traversal.

Problem :- Given a binary search tree, print its nodes in sorted order.

Solution Approach :-
The inorder traversal of a Binary Search Tree (BST) prints nodes in sorted order because of the inherent property of a BST: nodes in the left subtree have smaller values, and nodes in the right subtree have larger values. In the inorder traversal algorithm, the left subtree is visited first, followed by the current node, and then the right subtree. This order ensures that nodes are visited in ascending order, resulting in a sorted output.

Time complexity :- O(N), because the algorithm visits all the nodes in the given BST.

Space complexity :- O(1), as no extra space is needed.