Question: Can you please find the time complexity(Theta(?)) of this algorithm below? And explain how you can calculate it? def BiggestOutOfOrder(A, k): # YOUR CODE HERE

Can you please find the time complexity(Theta(?)) of this algorithm below? And explain how you can calculate it?

def BiggestOutOfOrder(A, k): # YOUR CODE HERE build_max_heap(A) return A[-k:]

def max_heapify(A,n,i): l = left(i) r = right(i) if l < n and A[l] > A[i]: largest = l else: largest = i if r < n and A[r] > A[largest]: largest = r if largest != i: A[i], A[largest] = A[largest], A[i] max_heapify(A,n,largest)

def left(i): return 2 * i + 1

def right(i): return 2 * i + 2

def build_max_heap(A): n = len(A) for i in range(n, -1,-1): max_heapify(A,n, i) for i in range(n-1,0,-1): A[0],A[i]=A[i],A[0] max_heapify(A,i, 0)

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!