Question: PLEASE ONLY FIX MY CODE UNDER simplepartition Thanks! Complete the implementation of a function boundedSort ) by completing the simplePatition function. Given an array a

PLEASE ONLY FIX MY CODE UNDER "simplepartition" Thanks!
Complete the implementation of a function boundedSort ) by completing the simplePatition function. Given an array a and a fixed
pivot element, it should partition the array "in-place" so that all elements pivot are on one side of the array and elements > pivot on the
other. You should not create a new array in your code.
In ]:
def swap(a,i,j):
assert {i}{len(a)}'{j}{len(a)}a[i],a[j]=a[j],a[i]i=0j=0a[j]i,ji=i+1j=j+1j=j+1i+1i+1a,kj(1,k)a,jj :
ifa[j]co pivot:
swap (a,i,j)
i=i+1
j=j+1
else:
j=j+1
swap (a,i+1, pivot)
return i+1
def boundedSort(a,k):
for jin range (1,k) :
simplePartition(a,j)
In[]:0j, f'accessing index {j} beyond end of array {len(a)}
a[i],a[j]=a[j],a[i]
def simplePartition(a, pivot):
## Todo: partition the array a according to pivot.
# Your array must be partitioned into two regions -c= pivot followed by elements > pivot
## Ifan element at the beginning of the array is already pivot in the beginning of the array, it should not
## be moved by the algorithm.
# your code here
i=0
j=0
while j :
ifa[j]co pivot:
swap (a,i,j)
i=i+1
j=j+1
else:
j=j+1
swap (a,i+1, pivot)
return i+1
def boundedSort(a,k):
for jin range (1,k) :
simplePartition(a,j)
In[]:0 len(a), f'accessing index {i} beyond end of array {len(a)}'
assert 0j, f'accessing index {j} beyond end of array {len(a)}
a[i],a[j]=a[j],a[i]
def simplePartition(a, pivot):
## Todo: partition the array a according to pivot.
# Your array must be partitioned into two regions -c= pivot followed by elements > pivot
## Ifan element at the beginning of the array is already pivot in the beginning of the array, it should not
## be moved by the algorithm.
# your code here
i=0
j=0
while j :
ifa[j]co pivot:
swap (a,i,j)
i=i+1
j=j+1
else:
j=j+1
swap (a,i+1, pivot)
return i+1
def boundedSort(a,k):
for jin range (1,k) :
simplePartition(a,j)
In[]:
 PLEASE ONLY FIX MY CODE UNDER "simplepartition" Thanks! Complete the implementation

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!