SlideShare a Scribd company logo
Each team works on assigned sorting algorithms and will give demonstration and PowerPoint
presentation on Nov. 16^th during lab class. Search internet for tutorials and source code in
python on sorting algorithms assigned to your team. Modify the python code to count the number
of comparisons and the number of swaps when sorting a random list of size n, n>=100, for
example, n = 100, 1000, 10000. To test your program use a small size of n for example, n = 10,
and print the list before and after sorting. Once confirmed the your program sorts correctly, try
larger size of n without print the list. In your presentation, explain how do the sorting algorithms
work and given their worst case and average case complexity, and include following table:
Submit the source code and presentation to D2L Assignment for Team Project 1 before
11:00PM. 11/16/2016 Sorting Algorithms: Selection sort, quick sort Insertion sort, shell sort
Bubble sort, merge sort Heap sort Radix sort
Solution
Selection Sort:
def selectionSort(list1):
for x in range(len(list1)-1,0,-1):
max_pos=0
for location in range(1,x+1):
if list1[location]>list1[max_pos]:
max_pos = location
temp = list1[x]
list1[x] = list1[max_pos]
list1[max_pos] = temp
list1 = [100,550,12,10,9]
selectionSort(list1)
print "Sorted List"
print(list1)
================================================
Output:
Sorted List
[9, 10, 12, 100, 550]
==================================================
Quck sort
def quickSort(list1):
quickSortHelper(list1,0,len(list1)-1)
def quickSortHelper(list1,left,right):
if left= pivot and r >= l:
r = r -1
if r < l:
done = True
else:
temp = list1[l]
list1[l] = list1[r]
list1[r] = temp
temp = list1[left]
list1[left] = list1[r]
list1[r] = temp
return r
list1 = [100,550,12,10,9]
quickSort(list1)
print(list1)
=============================================
Output:
[9, 10, 12, 100, 550]
=================================================
insertion sort:
def insertionSort(list1):
for i in range(1,len(list1)):
currentvalue = list1[i]
position = i
while position>0 and list1[position-1]>currentvalue:
list1[position]=list1[position-1]
position = position-1
list1[position]=currentvalue
list1 = [100,550,12,10,9]
insertionSort(list1)
print(list1)
===================================================
Output:
[9, 10, 12, 100, 550]
=================================================
Bubble sort:
def bubbleSort(list1):
for x in range(len(list1)-1,0,-1):
for i in range(x):
if list1[i]>list1[i+1]:
temp = list1[i]
list1[i] = list1[i+1]
list1[i+1] = temp
list1 = [100,550,12,10,9]
bubbleSort(list1)
print(list1)
======================================
Output:
[9, 10, 12, 100, 550]
====================================
def mergeSort(list1):
print("Splitting list ",list1)
if len(list1)>1:
mid = len(list1)//2
lefthalf = list1[:mid]
righthalf = list1[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i=0
j=0
k=0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
list1[k]=lefthalf[i]
i=i+1
else:
list1[k]=righthalf[j]
j=j+1
k=k+1
while i < len(lefthalf):
list1[k]=lefthalf[i]
i=i+1
k=k+1
while j < len(righthalf):
list1[k]=righthalf[j]
j=j+1
k=k+1
print("Merging ",list1)
list1 = [100,550,12,10,9]
mergeSort(list1)
print(list1)
========================================
Output:
('Splitting list ', [100, 550, 12, 10, 9])
('Splitting list ', [100, 550])
('Splitting list ', [100])
('Merging ', [100])
('Splitting list ', [550])
('Merging ', [550])
('Merging ', [100, 550])
('Splitting list ', [12, 10, 9])
('Splitting list ', [12])
('Merging ', [12])
('Splitting list ', [10, 9])
('Splitting list ', [10])
('Merging ', [10])
('Splitting list ', [9])
('Merging ', [9])
('Merging ', [9, 10])
('Merging ', [9, 10, 12])
('Merging ', [9, 10, 12, 100, 550])
[9, 10, 12, 100, 550]
===========================================
Heap sort
def heapsort( list1 ):
# convert list1 to heap
length = len( list1 ) - 1
Parent = length / 2
for i in range ( Parent, -1, -1 ):
downAdjust( list1, i, length )
# flatten heap into sorted array
for i in range ( length, 0, -1 ):
if list1[0] > list1[i]:
swap( list1, 0, i )
downAdjust( list1, 0, i - 1 )
def downAdjust( list1, first, last ):
largest = 2 * first + 1
while largest <= last:
# right child exists and is larger than left child
if ( largest < last ) and ( list1[largest] < list1[largest + 1] ):
largest += 1
# right child is larger than parent
if list1[largest] > list1[first]:
swap( list1, largest, first )
# move down to largest child
first = largest;
largest = 2 * first + 1
else:
return # force exit
def swap( A, x, y ):
tmp = A[x]
A[x] = A[y]
A[y] = tmp
list1 = [100,550,12,10,9]
heapsort(list1)
print(list1)
=====================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ python heap.py
[9, 10, 12, 100, 550]
============================================
Radix sort
def radixsort( list1 ):
div = 10
Length = False
tmp , placement = -1, 1
while not Length:
Length = True
# declare and initialize buckets
buckets = [list() for _ in range( div )]
# split list1 between lists
for i in list1:
tmp = i / placement
buckets[tmp % div].append( i )
if Length and tmp > 0:
Length = False
# empty lists into list1 array
a = 0
for b in range( div ):
buck = buckets[b]
for i in buck:
list1[a] = i
a += 1
# move to next digit
placement *= div
list1 = [100,550,12,10,9]
radixsort(list1)
print(list1)
============================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ python radix.py
[9, 10, 12, 100, 550]

More Related Content

Similar to Each team works on assigned sorting algorithms and will give demonstr.pdf

Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
Software Guru
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
Julian Hyde
 
Kotlin for Android Developers - 2
Kotlin for Android Developers - 2Kotlin for Android Developers - 2
Kotlin for Android Developers - 2
Mohamed Nabil, MSc.
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
goncharenko
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
Julian Hyde
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
Timothy McBush Hiele
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Asst.prof M.Gokilavani
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
Liang (Leon) Zhou
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language Md. Mahedi Mahfuj
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
tdc-globalcode
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
Roberto Pepato
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Philip Schwarz
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
GaneshPawar819187
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Python 培训讲义
Python 培训讲义Python 培训讲义
Python 培训讲义
leejd
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
Kevlin Henney
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
info706022
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
climatewarrior
 

Similar to Each team works on assigned sorting algorithms and will give demonstr.pdf (20)

Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
 
Kotlin for Android Developers - 2
Kotlin for Android Developers - 2Kotlin for Android Developers - 2
Kotlin for Android Developers - 2
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Python 培训讲义
Python 培训讲义Python 培训讲义
Python 培训讲义
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 

More from omarionmatzmcwill497

CenTable - Requirements Specification CenTable is a system for creati.pdf
CenTable - Requirements Specification CenTable is a system for creati.pdfCenTable - Requirements Specification CenTable is a system for creati.pdf
CenTable - Requirements Specification CenTable is a system for creati.pdf
omarionmatzmcwill497
 
Are silenced genes associated with high or low levels of DNA methyla.pdf
Are silenced genes associated with high or low levels of DNA methyla.pdfAre silenced genes associated with high or low levels of DNA methyla.pdf
Are silenced genes associated with high or low levels of DNA methyla.pdf
omarionmatzmcwill497
 
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdfA south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
omarionmatzmcwill497
 
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdfWrite an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
omarionmatzmcwill497
 
Write a program that will prompt a user to input their name(first .pdf
Write a program that will prompt a user to input their name(first .pdfWrite a program that will prompt a user to input their name(first .pdf
Write a program that will prompt a user to input their name(first .pdf
omarionmatzmcwill497
 
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
With a blow count of 14 the density of the soil is Select one 15e bit.pdfWith a blow count of 14 the density of the soil is Select one 15e bit.pdf
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
omarionmatzmcwill497
 
Which process(es) can move solutes against concentration gradients (.pdf
Which process(es) can move solutes against concentration gradients (.pdfWhich process(es) can move solutes against concentration gradients (.pdf
Which process(es) can move solutes against concentration gradients (.pdf
omarionmatzmcwill497
 
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
What role do piRNAs play  Serve as atemplate for transposon silencin.pdfWhat role do piRNAs play  Serve as atemplate for transposon silencin.pdf
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
omarionmatzmcwill497
 
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdfwhat was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
omarionmatzmcwill497
 
Three LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdfThree LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdf
omarionmatzmcwill497
 
There are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdfThere are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdf
omarionmatzmcwill497
 
The poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdfThe poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdf
omarionmatzmcwill497
 
Suppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdfSuppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdf
omarionmatzmcwill497
 
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdfPlease help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
omarionmatzmcwill497
 
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdfNEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
omarionmatzmcwill497
 
Problem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdfProblem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdf
omarionmatzmcwill497
 
Simplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdfSimplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdf
omarionmatzmcwill497
 
Our understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdfOur understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdf
omarionmatzmcwill497
 
Please Explain. Compute the worst case time complexity of the follow.pdf
Please Explain. Compute the worst case time complexity of the follow.pdfPlease Explain. Compute the worst case time complexity of the follow.pdf
Please Explain. Compute the worst case time complexity of the follow.pdf
omarionmatzmcwill497
 
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
omarionmatzmcwill497
 

More from omarionmatzmcwill497 (20)

CenTable - Requirements Specification CenTable is a system for creati.pdf
CenTable - Requirements Specification CenTable is a system for creati.pdfCenTable - Requirements Specification CenTable is a system for creati.pdf
CenTable - Requirements Specification CenTable is a system for creati.pdf
 
Are silenced genes associated with high or low levels of DNA methyla.pdf
Are silenced genes associated with high or low levels of DNA methyla.pdfAre silenced genes associated with high or low levels of DNA methyla.pdf
Are silenced genes associated with high or low levels of DNA methyla.pdf
 
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdfA south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
A south facing window is 2.1 m high and 4.2 m long. A horizontal diff.pdf
 
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdfWrite an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
Write an extended summary (They say”) of Sheryl Sandbergs Lean.pdf
 
Write a program that will prompt a user to input their name(first .pdf
Write a program that will prompt a user to input their name(first .pdfWrite a program that will prompt a user to input their name(first .pdf
Write a program that will prompt a user to input their name(first .pdf
 
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
With a blow count of 14 the density of the soil is Select one 15e bit.pdfWith a blow count of 14 the density of the soil is Select one 15e bit.pdf
With a blow count of 14 the density of the soil is Select one 15e bit.pdf
 
Which process(es) can move solutes against concentration gradients (.pdf
Which process(es) can move solutes against concentration gradients (.pdfWhich process(es) can move solutes against concentration gradients (.pdf
Which process(es) can move solutes against concentration gradients (.pdf
 
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
What role do piRNAs play  Serve as atemplate for transposon silencin.pdfWhat role do piRNAs play  Serve as atemplate for transposon silencin.pdf
What role do piRNAs play Serve as atemplate for transposon silencin.pdf
 
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdfwhat was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
what was the PRIMARY cause of the current Greece Crisis Excessive g.pdf
 
Three LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdfThree LR circuits are made with the same resistor but different induc.pdf
Three LR circuits are made with the same resistor but different induc.pdf
 
There are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdfThere are several things fundamentally wrong in this illustration. Po.pdf
There are several things fundamentally wrong in this illustration. Po.pdf
 
The poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdfThe poor are available to do the unpleasant jobs that no one .pdf
The poor are available to do the unpleasant jobs that no one .pdf
 
Suppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdfSuppose that 14 of people are left handed. If you pick two people a.pdf
Suppose that 14 of people are left handed. If you pick two people a.pdf
 
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdfPlease help me with these General Biology 1 (Bio 111) questions. You.pdf
Please help me with these General Biology 1 (Bio 111) questions. You.pdf
 
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdfNEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
NEED HELP ON C HOMEWORKIntroduction Programmers for a Better Tomo.pdf
 
Problem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdfProblem 14. Your probability class has 250 undergraduate students and.pdf
Problem 14. Your probability class has 250 undergraduate students and.pdf
 
Simplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdfSimplify each expression. Write all ansers without using negative ex.pdf
Simplify each expression. Write all ansers without using negative ex.pdf
 
Our understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdfOur understanding of genetic inheritance and the function of DNA i.pdf
Our understanding of genetic inheritance and the function of DNA i.pdf
 
Please Explain. Compute the worst case time complexity of the follow.pdf
Please Explain. Compute the worst case time complexity of the follow.pdfPlease Explain. Compute the worst case time complexity of the follow.pdf
Please Explain. Compute the worst case time complexity of the follow.pdf
 
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf3. Variance of exponential and uniform distributions(a) Compute Va.pdf
3. Variance of exponential and uniform distributions(a) Compute Va.pdf
 

Recently uploaded

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 

Recently uploaded (20)

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 

Each team works on assigned sorting algorithms and will give demonstr.pdf

  • 1. Each team works on assigned sorting algorithms and will give demonstration and PowerPoint presentation on Nov. 16^th during lab class. Search internet for tutorials and source code in python on sorting algorithms assigned to your team. Modify the python code to count the number of comparisons and the number of swaps when sorting a random list of size n, n>=100, for example, n = 100, 1000, 10000. To test your program use a small size of n for example, n = 10, and print the list before and after sorting. Once confirmed the your program sorts correctly, try larger size of n without print the list. In your presentation, explain how do the sorting algorithms work and given their worst case and average case complexity, and include following table: Submit the source code and presentation to D2L Assignment for Team Project 1 before 11:00PM. 11/16/2016 Sorting Algorithms: Selection sort, quick sort Insertion sort, shell sort Bubble sort, merge sort Heap sort Radix sort Solution Selection Sort: def selectionSort(list1): for x in range(len(list1)-1,0,-1): max_pos=0 for location in range(1,x+1): if list1[location]>list1[max_pos]: max_pos = location temp = list1[x] list1[x] = list1[max_pos] list1[max_pos] = temp list1 = [100,550,12,10,9] selectionSort(list1) print "Sorted List" print(list1) ================================================ Output: Sorted List [9, 10, 12, 100, 550] ================================================== Quck sort def quickSort(list1): quickSortHelper(list1,0,len(list1)-1)
  • 2. def quickSortHelper(list1,left,right): if left= pivot and r >= l: r = r -1 if r < l: done = True else: temp = list1[l] list1[l] = list1[r] list1[r] = temp temp = list1[left] list1[left] = list1[r] list1[r] = temp return r list1 = [100,550,12,10,9] quickSort(list1) print(list1) ============================================= Output: [9, 10, 12, 100, 550] ================================================= insertion sort: def insertionSort(list1): for i in range(1,len(list1)): currentvalue = list1[i] position = i while position>0 and list1[position-1]>currentvalue: list1[position]=list1[position-1] position = position-1 list1[position]=currentvalue list1 = [100,550,12,10,9] insertionSort(list1) print(list1) =================================================== Output: [9, 10, 12, 100, 550]
  • 3. ================================================= Bubble sort: def bubbleSort(list1): for x in range(len(list1)-1,0,-1): for i in range(x): if list1[i]>list1[i+1]: temp = list1[i] list1[i] = list1[i+1] list1[i+1] = temp list1 = [100,550,12,10,9] bubbleSort(list1) print(list1) ====================================== Output: [9, 10, 12, 100, 550] ==================================== def mergeSort(list1): print("Splitting list ",list1) if len(list1)>1: mid = len(list1)//2 lefthalf = list1[:mid] righthalf = list1[mid:] mergeSort(lefthalf) mergeSort(righthalf) i=0 j=0 k=0 while i < len(lefthalf) and j < len(righthalf): if lefthalf[i] < righthalf[j]: list1[k]=lefthalf[i] i=i+1 else: list1[k]=righthalf[j] j=j+1 k=k+1 while i < len(lefthalf):
  • 4. list1[k]=lefthalf[i] i=i+1 k=k+1 while j < len(righthalf): list1[k]=righthalf[j] j=j+1 k=k+1 print("Merging ",list1) list1 = [100,550,12,10,9] mergeSort(list1) print(list1) ======================================== Output: ('Splitting list ', [100, 550, 12, 10, 9]) ('Splitting list ', [100, 550]) ('Splitting list ', [100]) ('Merging ', [100]) ('Splitting list ', [550]) ('Merging ', [550]) ('Merging ', [100, 550]) ('Splitting list ', [12, 10, 9]) ('Splitting list ', [12]) ('Merging ', [12]) ('Splitting list ', [10, 9]) ('Splitting list ', [10]) ('Merging ', [10]) ('Splitting list ', [9]) ('Merging ', [9]) ('Merging ', [9, 10]) ('Merging ', [9, 10, 12]) ('Merging ', [9, 10, 12, 100, 550]) [9, 10, 12, 100, 550] =========================================== Heap sort def heapsort( list1 ): # convert list1 to heap
  • 5. length = len( list1 ) - 1 Parent = length / 2 for i in range ( Parent, -1, -1 ): downAdjust( list1, i, length ) # flatten heap into sorted array for i in range ( length, 0, -1 ): if list1[0] > list1[i]: swap( list1, 0, i ) downAdjust( list1, 0, i - 1 ) def downAdjust( list1, first, last ): largest = 2 * first + 1 while largest <= last: # right child exists and is larger than left child if ( largest < last ) and ( list1[largest] < list1[largest + 1] ): largest += 1 # right child is larger than parent if list1[largest] > list1[first]: swap( list1, largest, first ) # move down to largest child first = largest; largest = 2 * first + 1 else: return # force exit def swap( A, x, y ): tmp = A[x] A[x] = A[y] A[y] = tmp list1 = [100,550,12,10,9] heapsort(list1)
  • 6. print(list1) ===================================== Output: akshay@akshay-Inspiron-3537:~/Chegg$ python heap.py [9, 10, 12, 100, 550] ============================================ Radix sort def radixsort( list1 ): div = 10 Length = False tmp , placement = -1, 1 while not Length: Length = True # declare and initialize buckets buckets = [list() for _ in range( div )] # split list1 between lists for i in list1: tmp = i / placement buckets[tmp % div].append( i ) if Length and tmp > 0: Length = False # empty lists into list1 array a = 0 for b in range( div ): buck = buckets[b] for i in buck: list1[a] = i a += 1 # move to next digit placement *= div list1 = [100,550,12,10,9] radixsort(list1)