Implement 5 functions in Python that would sort an unsorted list, i.e • def bubble_sort(my_list): • def selection_sort(my_list): • def insertion_sort(my_list): • def quick_sort(mylist): • def insertion_sort(mylist, left, right): Provide a main that uses each of the above functions to sort a list of length 100 and make sure it works as expected Step 2 Add lines of code to the above functions so that apart from sorting the received list, it calculates T(n) and returns it. This means that each of the above functions will have a return value which is the exact number of operations executed to perform the sort. Use a main to test yout T(n) calculation. A good way of testing your T(n) is this. Send a best case scenario, a worst case scenario and an average scenario to your sort function and see what numbers come out for your T(n). Explain what best, worst and average case scenarios will be for a sorting algorithm. Step 3 Use the sort functions with T(n) calculation feature to plot T(n) vs. n for a wide range of list sizes. Say 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000, 10000000. Make sure you use a WORST CASE scenario for your list so that your T(n) is a good reflection of O(n). Do you see your curves aligned with what we learnt about the performance of the sort algorithms Step 4 Using time library in python, time your sort algorithms for the same list sizes that you plotted in step 3 and this time plot algrithm completion time vs n. Interpret the results while compared to the step 3 plot and compared to your knowledge of the algorithm's performances. Don't forget to use WORST CASE scenario. Example for Step 2 in bubble sort: def bubble_sort (my_list): steps = 0 for i in range (0, len (my_list) - 1): for j in range (0, len (my_list) - 1 - i): if my list[j] > my_list[j + 1]: steps += 4 # 4 operations, 3 for the swap and one for the comparison my_list[j], my_list[j + 1] = my_list[j + 1], my_list[j] return steps Code to create a random list of a specific size for steps 3 and 4: import random listSize = 50 rand_list = [random.randint (0,101) for val in range (listSize)] rand_list.sort (reverse=True) print("steps needed for sorting: {}".format (bubble sort (rand list)))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Implement 5 functions in Python that would sort an unsorted list, i.e
def bubble_sort(my_list):
def selection_sort(my_list):
def insertion_sort(my_list):
def quick_sort(mylist):
def insertion_sort(mylist, left, right):
Provide a main that uses each of the above functions to sort a list of length 100 and make sure it works as expected
Step 2
Add lines of code to the above functions so that apart from sorting the received list, it calculates T(n) and returns it. This means that each of the above functions will have a
return value which is the exact number of operations executed to perform the sort.
Use a main to test yout T(n) calculation. A good way of testing your T(n) is this. Send a best case scenario, a worst case scenario and an average scenario to your sort
function and see what numbers come out for your T(n). Explain what best, worst and average case scenarios will be for a sorting algorithm.
Step 3
Use the sort functions with T(n) calculation feature to plot T(n) vs. n for a wide range of list sizes. Say 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000,
10000000. Make sure you use a WORST CASE scenario for your list so that your T(n) is a good reflection of O(n). Do you see your curves aligned with what we learnt
about the performance of the sort algorithms
Step 4
Using time library in python, time your sort algorithms for the same list sizes that you plotted in step 3 and this time plot algrithm completion time vs n. Interpret the results
while compared to the step 3 plot and compared your knowledge of the algorithm's performances. Don't forget to use WORST CASE scenario.
Example for Step 2 in bubble sort:
def bubble_sort (my_list):
steps = 0
for i in range (0, len (my_list) - 1):
for j in range (0, len (my_list) - 1 - i):
if my_list[j] > my_list[j + 1]:
steps += 4 # 4 operations, 3 for the swap and one for the comparison
my_list[j], my_list[j + 1] = my_list[j+1], my_list[j]
return steps
Code to create a random list of a specific size for steps 3 and 4:
import random
listSize = 50
rand_list = [random.randint (0,101) for val in range (listSize)]
rand_list.sort (reverse=True)
print("steps needed for sorting: {}". format (bubble_sort (rand_list)))
Transcribed Image Text:Implement 5 functions in Python that would sort an unsorted list, i.e def bubble_sort(my_list): def selection_sort(my_list): def insertion_sort(my_list): def quick_sort(mylist): def insertion_sort(mylist, left, right): Provide a main that uses each of the above functions to sort a list of length 100 and make sure it works as expected Step 2 Add lines of code to the above functions so that apart from sorting the received list, it calculates T(n) and returns it. This means that each of the above functions will have a return value which is the exact number of operations executed to perform the sort. Use a main to test yout T(n) calculation. A good way of testing your T(n) is this. Send a best case scenario, a worst case scenario and an average scenario to your sort function and see what numbers come out for your T(n). Explain what best, worst and average case scenarios will be for a sorting algorithm. Step 3 Use the sort functions with T(n) calculation feature to plot T(n) vs. n for a wide range of list sizes. Say 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000, 10000000. Make sure you use a WORST CASE scenario for your list so that your T(n) is a good reflection of O(n). Do you see your curves aligned with what we learnt about the performance of the sort algorithms Step 4 Using time library in python, time your sort algorithms for the same list sizes that you plotted in step 3 and this time plot algrithm completion time vs n. Interpret the results while compared to the step 3 plot and compared your knowledge of the algorithm's performances. Don't forget to use WORST CASE scenario. Example for Step 2 in bubble sort: def bubble_sort (my_list): steps = 0 for i in range (0, len (my_list) - 1): for j in range (0, len (my_list) - 1 - i): if my_list[j] > my_list[j + 1]: steps += 4 # 4 operations, 3 for the swap and one for the comparison my_list[j], my_list[j + 1] = my_list[j+1], my_list[j] return steps Code to create a random list of a specific size for steps 3 and 4: import random listSize = 50 rand_list = [random.randint (0,101) for val in range (listSize)] rand_list.sort (reverse=True) print("steps needed for sorting: {}". format (bubble_sort (rand_list)))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education