You can find the kth smallest element in a BST in O(n) time from an inorder iterator.

Question:

You can find the kth smallest element in a BST in O(n) time from an inorder iterator. For an AVL tree, you can find it in O(log n) time. To achieve this, add a new data field named size in AVLTreeNode to store the number of nodes in the subtree rooted at this node. Note the size of a node v is one more than the sum of the sizes of its two children. Figure 26.12 shows an AVL tree and the size value for each node in the tree.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: