Question: Write a Python program Using your time efficiency function , measure the execution times of both insertion and merge sorting algorithms using the attached data

Write a Python program

Using your time efficiency function , measure the execution times of both insertion and merge sorting algorithms using the attached data files (one with 1,000 integers and the other with 1,000,000 integers ).

In addition, you also compute and display the total number of comparisons to complete each sorting algorithm along with time efficiencies.

  • 1,000,000 integers are in rand1000000.txtWrite a Python program Using your time efficiency function , measure the ,
  • 1,000 integers are in rand1000.txtexecution times of both insertion and merge sorting algorithms using the attached

    The insertion sort with 1,000,000 integers takes really long time (around 20 hours). This makes difficult to complete the sorting algorithm to the end on a personal computer. Below is how I would do it.

    1). On a Unix (Linux) server like csegrid machine, copy the program.

    2). Add the following line at the very first line of the program and save the file. This basically tells the Unix OS to run /user/bin/python3 with the Python script (program) in the file. "#!" in this line of code is called "shebang" ('sh' [Unix Bourne shell] + bang , or hash + bang)

    #!/usr/bin/python3

    3). On the command line, at input prompt, enter the following Unix command to make the file (say "insertionSort.py") executable.

    $ chmod +x insertionSort.py

    4). Run the following command from the command line to run the code in background.

    $ nohup insertionSort.py > hw2sort.txt &

    This will run "insertionSort.py" in background by adding "&" at the end of command line. Also the output of the command will be redirected to and stored in hw2sort.txt file instead of displaying on the display. "nohup" at the beginning of the command line tells Unix OS to continue to execute the command at the background even if the current login shell ends (which means you log out from the shell and terminates your putty session).

    5). Also you may consider adding following lines to test all the data sizes in one test run for extra credit points

    fileNames = ["rand1000.txt", "rand10000.txt", "rand100000.txt", "rand250000.txt" , "rand500000.txt", "rand1000000.txt" ] for name in fileNames :

    [your codes ..]

Transcribed image text

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!