VOOZH about

URL: https://www.geeksforgeeks.org/dsa/kth-smallest-element-in-bst-using-o1-extra-space/

⇱ K'th smallest element in BST using O(1) Extra Space - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

K'th smallest element in BST using O(1) Extra Space

Last Updated : 23 Jul, 2025

Given a Binary Search Tree (BST) and a positive integer k, find the k’th smallest element in the Binary Search Tree. 

Example:

Input: k = 3

πŸ‘ th-Largest-element-in-BST

Output: 10
Explanation:The inorder traversal of given BST is [4, 8, 10, 12, 14, 20, 22] and its 3rd smallest element is 10.

Approach:

The idea is to perform in-order traversal using Morris Traversal Algorithm while maintaining the count of nodes visited. When count becomes equal to k, return the node value.


Output
10

Time Complexity: O(k)
Auxiliary Space: O(1)

Related Article:


Comment