Рет қаралды 47,232
This video explains a very important problem which is to find the Kth smallest element in a binary search tree. This is a very common programming interview question for most companies and it can be solved by many techniques. I have shown 3 methods to solve this in increasing order of optimizations. The first method is the simplest which is done just by inorder traversal and storing the elements in an array and returning the (K-1)th index element as answer. The second method uses recursion/stack to solve the problem. The third method is the most optimized approach and it uses a special BST property to find the Kth smallest element in just O(Height) time. I have also explained the CODE at the end of the video. CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
LinkedIn: / surya-pratap-kahar-47b...
CODE LINK: gist.github.com/SuryaPratapK/...
SIMILAR PROBLEMS:
Kth largest element in an array: • Kth largest element in...
Check if a tree is bst or not: • Check if a tree is bst...