Question: Mod 7 Lab: Which sorting algorithm is which? Differentiate 5 sorting algorithms ( bubble , selection, insertion, merge, and quick ) based on how long
Mod Lab: Which sorting algorithm is which?
Differentiate sorting algorithms bubble selection, insertion, merge, and quick based on how long
they take to sort certain lists.
When you submit a file called numbers.txt to Gradescope, it will sort the numbers inside with these
algorithms, aliased as alga algb algc algd and alge:
n
alg t ms
alga
algb
algc
algd
alge
You need to
Create lists of different lengths and patterns
Determine which alias corresponds to which sorting algorithm
Answers
Write your answers in answers.py It contains a dictionary where the keys are the aliased algorithms; you
just need to enter the correct values bubbleselectioninsertionmerge or quick:
answers alga: 'algb: 'algc: 'algd: 'alge:
Lab Notes
generatenumbers.py contains code to automate the generation of numbers.txt
Each algorithm is used exactly once.
The bubble and insertion sorts are adaptive they can sort in On in the best case.
The quicksort algorithm always uses the last element in a sublist as the pivot.
The largest list you can create is items due to resource constraints on Gradescope.
Submitting
Students must submit individually by the due date typically Sunday at : pm EST to receive credit.
Grading
This assignment is entirely autograded: points per correct algorithm
code answers.py:
# Include your answers for this lab in the dictionary below.
# The keys of the dictionary are the prenumbered algorithms.
# The values are your answers. Use:
# 'bubble'
# 'selction'
# 'insertion'
# 'merge'
# 'quick'
# #For instance, if you though all the algorithms were bubble sort they are not this file should read:
# answers alga: 'bubble',
# 'algb: 'bubble',
# 'algc: 'bubble',
# 'algd: 'bubble',
# 'alge: 'bubble'
# Fill in your answers as the values in the dict below
answers alga:
'algb:
'algc:
'algd:
'alge:
validans bubble 'selection', 'insertion', 'merge', 'quick'
# Run this file in terminal to see if you used the correct formatting in your answer.
for k v in answers.items:
if v not in validans:
raise ValueErrorfValue v for key k is not in validans
printValid answer! Find out if it's right after the due date."
code generatenumbers.py:
# This program generates a list of numbers and writes them to a file.
import random
##### Generate list of numbers #####
n # Max is due to memory constraints with quicksort
L randomrandint n for i in rangen
##### Create file to write to #####
f openfnumberstxtw
##### Write numbers to file #####
for item in L:
fwritestritem
fwrite
#### Close the file ####
fclose
file name : numbers.txt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
