Question: Problem 1 [10 + 20 = 30 pts] The code for the selection algorithm has been uploaded to elearn. As pointed out in class, the
Problem 1 [10 + 20 = 30 pts] The code for the selection algorithm has been uploaded to elearn. As pointed out in class, the code is incorrect because there may be multiple elements equal to the one we are partitioning around (x) and while the counts lt, eq, gt are computed correctly, the x may not necessarily occur where they should. On paper submit as problem 1, an example where this incorrect code may lead to incorrect result. Also, change the code (dont change the function names etc.) to fix this. Your modified code should also run the partitioning in linear time. This code should be submitted on dropbox.![Problem 1 [10 + 20 = 30 pts] The code for the](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef434c1eb7c_36366ef434b9a91a.jpg)

i fimport random def swap (L,i,j): "I'Swap list positions i and j" t = L[i] L[i] = L[j] L[j] = t 9 def partition (L): n = len (L) idx = random.randrange(n) #put L[idx] into oth position swap (1,0, idx) x = L[0] #It is number of elements less than L[idx], eq is number of elements equal #gt is number of elements greater than L[idx] (lt,eq,gt) = (0,1,0) (ij) = (0,1) while (j
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
