Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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