Graphs the running times of insertion sort and merge sort algorithms that sort data from a text file in descending order. Homework assignment from CS 325 – Analysis of Algorithms at Oregon State University.
mergesort.py
and insertsort.py
: These use the necessary functions to read data from the data.txt
file, sort the data, and then write the data out to their respective insert.out
and merge.out
files.
mergeTime.py
and insertTime.py
: Uses the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, …. Then outputs the array size n and time to the terminal.
To run mergesort.py
and insertsort.py
:
- The file
data.txt
needs to be in the same directory asmergesort.py
andinsertsort.py
. - The
data.txt
file structure follows:- First value of each line is the number of integers that need to be sorted, followed by the integers.
- Example values for
data.txt
:4 19 2 5 11 8 1 2 3 4 5 6 1 2
- The output will be written to files called
merge.out
andinsert.out
in the same directory asmergesort.py
andinsertsort.py
.
To run mergeTime.py
and insertTime.py
:
- Run
mergeTime.py
andinsertTime.py
. - Array size and runtime will be printed to the screen.