Question: 1. Heaps Give an O(1) algorithm for finding the third-smallest element in a min-heap. Give your answer using pseudocode or clear English with a diagram.
1. Heaps Give an O(1) algorithm for finding the third-smallest element in a min-heap. Give your answer using pseudocode or clear English with a diagram. Prove your running time bound.
2. Trees Prove that red-black trees are approximately balanced. (Hint: use the trees properties to show that it cant get too unbalanced.)
3. Quicksort What is the running time of Quicksort when all elements of the input array have the same value?
4. Trees The pseudocode to find the number of nodes in a tree is as follows:
What is the worst-case runtime for a call to size(root) in a tree with n nodes? What is the best-case runtime?
Algorithm 1 size(x) 1: if x= nil then 2: return 0 3: return 1 + size(x.left) + SIzE(x.right)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
