How to find the Nth largest node in a BST?
Do I keep a count variable while doing In Order Traversal of a BST? Return the element when the count = N???
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See my answer here. You can do this in
O(log n)on average where n = number of nodes. Worst case is stillO(n)IF the tree isn’t balanced (alwaysO(log n)if it is balanced however). In order traversal is alwaysO(n)however.