Question: 2 Written Question 2 (25 marks) A binary tree is ideally weight balanced if, for every node x in the tree, the number of nodes

 2 Written Question 2 (25 marks) A binary tree is ideally

2 Written Question 2 (25 marks) A binary tree is ideally weight balanced if, for every node x in the tree, the number of nodes in its two subtrees differs by at most 1. 1. (10 marks) Give an algorithm with worst case running time in O(n) that, given a sorted array of n elements, constructs an ideally weight balanced binary search tree. Briefly justify the correctness of your algorithm and why it runs in O(n) time in the worst case. 2. (10 marks) Give an algorithm which has a worst case running time in O(n) that, given an n node binary search tree, transforms it into an ideally weight balanced binary search tree for the same elements. Briefly justify the correctness of your algorithm and why it runs in O(n) time in the worst case. 3. (5 marks) Prove that there is no O(n) time comparison based algorithm that, given an unsorted array of n elements, constructs an ideally balanced binary search tree

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!