You are on page 1of 2

Analysis of Algorithms (Fall 2019)

Assignment 2
Topic: Comparison of Insertion and Merge Sort
Reading Content for Assignment: Chapter 2(2.3) of Introduction to Algorithms by Cormen
Deadline: September 15, 2019 6:00 PM
Tasks:
In this assignment, you will use the first assignment and implement the following tasks in the first
assignment.
• Implement Merge sort in C++ or C#. No other language is allowed.
• Generate the 1000 random numbers in the range(1-106)
• Feed the random numbers to merge sort to sort these numbers.
• Store the sorted random numbers(one number per line) in a text file named (sorted.txt).
• Now play with the number of integers fed to merge sort. Increase the random numbers and
generate a csv file (named results.csv) in the following format
Number of integers Insertion sort time in sec Merge sort time in sec
1000
5000
10000
20000
30000
40000
50000
60000
100000
500000
1000000

Things to Remember (Not following the instruction will result in ZERO MARKS):
• You have to calculate to time the algorithm takes to sort the array. This time should not
include the time for the generation of random numbers and writing the numbers in sorted
array
• For insertion sort, the definition should be like this.
void InsertionSort(int[] arr, int startIndex, int endIndex)
The function should sort the elements of array arr from startIndex to endIndex.
• For merge sort, the definition should be like this.
void MergeSort(int[] arr, int startIndex, int endIndex)
The function should sort the elements of array arr from startIndex to endIndex.
• If you do not follow the definition, your assignment will not be checked.
• Properly commented code and clean code will get more marks.
What to Submit:
You are required to submit only 2 files zipped in a folder. No file other than zip will be accepted.
• In case of C++, ps2.cpp and in case of C# ps2.cs
• result.csv

You might also like