Question: Let T be a tree with n items. Each node v has space for storing v:size, the number of items stored in Tv, the subtree

Let T be a tree with n items. Each node v has space for storing v:size, the number of items stored in Tv, the subtree rooted at v.

Q1. Design an algorithm that populates v:size for all nodes v of T in O(n) time.

Q2. Suppose T is a binary search tree and the size values of the nodes have been filled. Write a pseudocode for SmallestKey(T; k), a method that returns the item with the kth smallest key in T in O(h) time. If there are multiple items associated with the kth smallest key, return just one item. Warning: the inorder traversal is not an option here because it runs in O(n) time.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!