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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started