Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions