Question: You can assume that the programming language is Python. Consider the following code for checking if the input array A is a max-heap: er A

 You can assume that the programming language is Python. Consider the

following code for checking if the input array A is a max-heap:

er A co 1 // Assume arrays are zero-indexed 2 17 and

A.size() returns number of elements in A 3 CheckMaxHeap (A): 4 for

i from 0 to floor (A.size()/2)-1: if CheckMax HeapHelper (A, i) ==

False return false return True co v 11 9 CheckMaxHeapHelper (A, i):

You can assume that the programming language is Python.

Consider the following code for checking if the input array A is a max-heap: er A co 1 // Assume arrays are zero-indexed 2 17 and A.size() returns number of elements in A 3 CheckMaxHeap (A): 4 for i from 0 to floor (A.size()/2)-1: if CheckMax HeapHelper (A, i) == False return false return True co v 11 9 CheckMaxHeapHelper (A, i): 10 if 2i+1 A[i]: return false if 2i+2 A[i]: return false 16 return True (8 points) Now consider an array A with five elements (suppose A is (-indexed). Suppose the elements of A are filled with a random permutation of {1, 2, 3, 4, 5). What is the probability that CheckMaxHeap (A) returns True? If we run CheckMaxHeap(A), what is the expected number of times CheckMaxHeapHelper is called

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!