Kth Smallest / Largest in BST
Learn Kth Smallest / Largest in BST (Trees, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Using Inorder's Sorted Property Since inorder traversal of a BST visits nodes in ascending order, the Kth SMALLEST element is simply the Kth value visited by inorder - stop as soon as a counter reaches K, no need to traverse the whole tree.
More lessons in Trees
- Binary Tree
- Binary Search Tree - BST
- Full / Complete / Perfect Binary Tree
- Balanced Tree
- Tree Traversal - Preorder
- Tree Traversal - Inorder
- Tree Traversal - Postorder
- Tree Traversal - Level Order
- Recursive Traversal
- Iterative Traversal
- Height / Depth
- Diameter of a Tree
- Lowest Common Ancestor
- Path Sum
- Tree View - Left View
- Tree View - Right View
- Tree View - Top View
- Tree View - Bottom View
- Boundary Traversal
- Vertical Traversal
- Zigzag Traversal
- Serialize / Deserialize a Tree
- BST Operations
- BST Validation
- Morris Traversal