Question: I am trying to solve this question below. The time complexity is super important, WORST CASE COMPLEXITY MUST BE Theta(nk) . Also, we are not
I am trying to solve this question below.
The time complexity is super important, WORST CASE COMPLEXITY MUST BE Theta(nk). Also, we are not allowed to use ".sort" or other python build-in functions. We can only use pop, remove, append...
I tried to solve this question by finding and removing Len(A)-k minimum elements from my array with this method, the order will not be changed and I can have the k largest elements. I can remove the first min element but I can not remove Len(A)-k minimum elements. You can see my code below. Please help me to improve my code and please do not copy-paste sum google examples. PLEASE READ MY EXPLANATIONS, IF ANYTHING YOU DID NOT UNDERSTAND ASK ME, I CAN EXPLAIN MORE ABOUT IT.

Note: WE ARE NOT ALLOWED TO CHANGE FUNCTION NAME OR INPUTS.... PLEASE WORK INSIDE OF THIS FUNCTION ONLY TY
2(b) Now suppose that the order of the array was important. Design and implement an algorithm that returns an array of the k largest elements of A in their original order, and it should run in Onk) time. For example, BiggestinOrder([0,5,1,3,4), 3) should return (5,3,4]. def BiggestInOrder(A, k): # YOUR CODE HERE min=A[0] 1=len (A) for i in range(len (A)): if A[i]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
