Skip to content

Latest commit

 

History

History
 
 

kth_smallest_element_in_a_bst

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Problem

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

Follow up: What if the BST is modified (insert/delete operations) often and you need to find the kth smallest frequently? How would you optimize the kthSmallest routine?

Hint:

Try to utilize the property of a BST. What if you could modify the BST node's structure? The optimal runtime complexity is O(height of BST).

Comments

The author tries to make you answer "order statistic tree" for the question follow-up, found in "Introduction to algorithms"