Question: Problem 3. (12 marks) Recall that in a binary tree each node has at most 2 children. Suppose T is a binary tree with ITI

Problem 3. (12 marks) Recall that in a binary tree each node has at most 2 children. Suppose T is a binary tree with ITI = n (ie, has n nodes). For every node u we use Lu and Ru to denote the left subtree and right subtree of v, respectively. We say the subtree rooted at v is nearly balanced if IRl/L| 2, i.e. the sizes of the two subtrees are within a factor two of each other. a. (5 marks) Suppose that the root of T is nearly balanced. What is the maximum height of T in terms of n? Explain why. b. (7 marks) We say the whole tree is nearly balanced if for every node v of T, the subtree rooted at v is nearly balanced. Denote h as the height of T. Show that if T is nearly balanced then h E O(log n) by first showing that h log nl Problem 3. (12 marks) Recall that in a binary tree each node has at most 2 children. Suppose T is a binary tree with ITI = n (ie, has n nodes). For every node u we use Lu and Ru to denote the left subtree and right subtree of v, respectively. We say the subtree rooted at v is nearly balanced if IRl/L| 2, i.e. the sizes of the two subtrees are within a factor two of each other. a. (5 marks) Suppose that the root of T is nearly balanced. What is the maximum height of T in terms of n? Explain why. b. (7 marks) We say the whole tree is nearly balanced if for every node v of T, the subtree rooted at v is nearly balanced. Denote h as the height of T. Show that if T is nearly balanced then h E O(log n) by first showing that h log nl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
