Data structures with python Modify the three sorting routines listed below in a
ID: 3764627 • Letter: D
Question
Data structures with python
Modify the three sorting routines listed below in a way that will allow you to analyze their performance. This can bedone by counting the number of comparisins and/or counting the number of swaps made. The more data you creat, the better you analysis will be. Test each sorting routine using different sizes of lists (1000 , 10000, 100000) .
Modify the sort routines and test program to generate the data you need .
sort Routines you must use :
(bubble , selection , quick )
Explanation / Answer
def bsort(l):
for i in range(len(l)-1):
for j in range(len(l)-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
return l
def ssort(l):
i=0
while i<(len(l)-1):
m=i
j=i+1
while j<len(l):
if l[m]>l[j]:
m=j
j=j+1
t=l[i]
l[i]=l[m]
l[m]=t
i=i+1
return l
def partition (a,x,left,right):
i=left
j=right
while(i<=j):
if(a[i]<=x):
i=i+1
else:
a[i],a[j]=a[j],a[i]
print i
print a
j=j-1
p=j
print p
return p
def qsort(l):
if(len(l)<2): return l
p=partition(l,l[0],1,len(l)-1)
l[0],l[p]=l[p],l[0]
return qsort(l[:p])+[l[p]]+qsort(l[p+1:])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.