Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert this pseudo code into python 3: The pseudo code: function partition(A,start,stop) Set pivot = A[stop] Set i=start for j from start to stop by

Convert this pseudo code into python 3:

The pseudo code:

function partition(A,start,stop)

Set pivot = A[stop]

Set i=start

for j from start to stop by 1 do

if not (A[j] > pivot) then

Swap A[i] and A[j]

Add 1 to i

end if

end for

Swap A[i] and A[stop]

return i

end function

This following program below is a separate file that tests the partition program (the pseudo code above)

from part import partition: def checkP(X,start,stop,p): pivot = X[p] for v in range(0,p): if X[v] > pivot: return False for v in range(p,stop+1): if X[v] < pivot: return False return True def runTest(test,input): data = test start = input[0] stop = input[1] print("Partitioning List:") print(data) print("Start=%d, Stop=%d"%(start,stop)) p=partition(data,start,stop) if checkP(data,start,stop,p): print("Partition is valid.") else: print("Partition is invalid.") print("After Partition:") print(data)

if __name__=="__main__": T=[ [] for x in range(0,6)] inputs = [ [] for x in range(0,6)] #Simple test T[0]=[1,9,2,8,3,7,4,6] inputs[0]=[0,7] #Left Border T[1]=[1,9,2,8,3,7,4,6] inputs[1]=[0,2] #Right Border T[2]=[1,9,2,8,3,7,4,6] inputs[2]=[5,7] #Middle Case T[3]=[1,9,2,8,3,7,4,6] inputs[3]=[2,5] #Bad Case Left T[4]=[1,2,3,4,5,6,7,8,9] inputs[4]=[0,8] #Bad Case Right T[5]=[9,8,7,6,5,4,3,2,1] inputs[5]=[0,8] #Run tests counter=0 while counter < len(T): print("Test %d of %d."%(counter+1,len(T))) runTest(T[counter],inputs[counter]) counter+=1

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

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions