The question is in bold the below information is just extra as a guide  Use perf_count to generate a list of data, where the ith entry is the time tm(i) necessary for merge-sort to sort lists of randomly chosen elements of length 2 i for i = 1, . . . , 10. Using ideas from 8.1. Sorting experiments First we need to generate some shued lists to sort. The shuffle method from the random module is used to randomise a list. For example the code from random import shuffle mylist = list(range(1, n+1)) random.shuffle(mylist) will produce a randomly shuffled list of all the integers from 1 to n inclusive. The following code provides a way to generate list of different lengths (in this case of length 2i for different i) with the time it takes to sort each: listlengths = [] sorttimelist = [] for i in range(1, 5):    listlengths.append(2**i)    mylist = list(range(2**i))    shuffle(mylist)    # here define sorttime (how long it takes to sort the list)     sorttimelist.append(sorttime) To test how long a sorting algorithm takes to sort a large list of numbers we will import and use the perf_counter() function from the time module. This function returns the number of seconds since some reference time. For example, the code: time_start = time.perf_counter() selectionsort(mylist) time_end = time.perf_counter() sorttime = time_end - time_start will store the time needed for selection sort to sort mylist. You are only timing the sorting process  so be careful not to include the time to create the unsorted list in your timing!

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

The question is in bold the below information is just extra as a guide 

Use perf_count to generate a list of data, where the ith entry is the time tm(i) necessary for merge-sort to sort lists of randomly chosen elements of length 2 i for i = 1, . . . , 10. Using ideas from 8.1. Sorting experiments

First we need to generate some shued lists to sort. The shuffle method from the random module is used to randomise a list. For example the code

from random import shuffle

mylist = list(range(1, n+1))

random.shuffle(mylist)

will produce a randomly shuffled list of all the integers from 1 to n inclusive. The following code provides a way to generate list of different lengths (in this case of length 2i for different i) with the time it takes to sort each:

listlengths = []

sorttimelist = []

for i in range(1, 5):

   listlengths.append(2**i)

   mylist = list(range(2**i))

   shuffle(mylist)

   # here define sorttime (how long it takes to sort the list)

    sorttimelist.append(sorttime)

To test how long a sorting algorithm takes to sort a large list of numbers we will import and use the perf_counter() function from the time module. This function returns the number of seconds since some reference time. For example, the code:

time_start = time.perf_counter()

selectionsort(mylist)

time_end = time.perf_counter()

sorttime = time_end - time_start

will store the time needed for selection sort to sort mylist. You are only timing the sorting process  so be careful not to include the time to create the unsorted list in your timing!

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Mergesort
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
  • SEE MORE 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