Question: Write a second Python program to sort numbers. The program must carry out several steps, and should be designed with maximum modularity. First, the program

Write a second Python program to sort numbers. The program must carry out several steps,

and should be designed with maximum modularity.

First, the program generates random numbers and writes them to a file. The user is asked t o

input the range over which the random numbers will be generated, and how many numbers

are desired. The Python pseudorandom number generator is then used to create random

numbers in accordance with these guidelines, and written to a file, one number per line.

Next, the file is opened and sorted, and the sorted output written to a new file. You should

write a

function which carries out sorting using selection sort to do this work. Then, the

original (unsorted) file of random numbers is opened again and sorted a second time, but this

time sorted by using merge sort. Write a separate function to carry out the merge sort

routine, and write the sorted numbers to a third file.

As a learning experience, we want to compare how long the two sorting techniques take. To

do this, we use the Python time module to measure the elapsed time required to do the

sorting. Here is a high level pseudocode of the algorithm intended to be used by the main

program:

Prepare a file of random numbers

Start a timer

Sort the random numbers using selection sort

Stop the timer and note the elapsed time

Start a timer

Sort the random numbers using merge sort

Stop the timer and note the elapsed time

The screen output of the main program should report the quantity of numbers that were sorted, and how long each sorting technique required to do the work. 2 of 3 two samples, with the larger one being at least one thousand times bigger than the smaller. Again, make sure your program has a good modular design and is robust.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!