Question: 4. (5 pts.) Let T be a tree ADT. Suppose each node has space for storing v.size, where v.size is equal to the number of


4. (5 pts.) Let T be a tree ADT. Suppose each node has space for storing v.size, where v.size is equal to the number of nodes in the subtree of v. Suppose T has n nodes. a. (2.5 pts.) Design an O(n)-time algorithm that computes the v.size value for all the nodes in T. b. (2.5 pts.) Suppose T is actually a proper binary tree. You've done part a already. We say a node v is E-skewed if the size difference between its left and right subtree is at least e, where e is some positive integer. Design an O(n)-time algorithm that outputs a node that is e-skewed but none of its descendants are e-skewed. 4. (5 pts.) Let T be a tree ADT. Suppose each node has space for storing v.size, where v.size is equal to the number of nodes in the subtree of v. Suppose T has n nodes. a. (2.5 pts.) Design an O(n)-time algorithm that computes the v.size value for all the nodes in T. b. (2.5 pts.) Suppose T is actually a proper binary tree. You've done part a already. We say a node v is E-skewed if the size difference between its left and right subtree is at least e, where e is some positive integer. Design an O(n)-time algorithm that outputs a node that is e-skewed but none of its descendants are e-skewed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
