Given root of binary search tree and K as input, find K-th smallest element in BST.
For example, in the following BST, if k = 3, then output should be 10, and if k = 5, then output should be 14.
Method 1: Using Inorder Traversal.
Inorder traversal of BST retrieves elements of tree in the sorted order. The inorder traversal uses stack to store to be explored nodes of tree. The idea is to keep track of popped elements which participate in the order statics. Hypothetical algorithm is provided below,
Time complexity: O(n) where n is total nodes in tree..
http://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/