Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.txtimage text in transcribed ,
  • 1,000 integers are in rand1000.txtimage text in transcribed

    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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago