Find the kth largest element in a Binary Search Tree
public static void getElement(Tree root, int k){
//Base condition
if(root == null)
return;
getElement(root.right, k); //first traverse the right sub tree
if(++index == k){
System.out.println(root.data);
return;
}
getElement(root.left, k); //then traverse the left sub tree
}
Read full article from Tech Savvy: Find the kth largest element in a Binary Search Tree
public static void getElement(Tree root, int k){
//Base condition
if(root == null)
return;
getElement(root.right, k); //first traverse the right sub tree
if(++index == k){
System.out.println(root.data);
return;
}
getElement(root.left, k); //then traverse the left sub tree
}
Read full article from Tech Savvy: Find the kth largest element in a Binary Search Tree