Question
1.1 Experiment: Merge Sort vs. Insertion Sort The goal of this rst experiment is to compare empirically time complexities of Insertion sort vs. Merge sort.
1.1 Experiment: Merge Sort vs. Insertion Sort
The goal of this first experiment is to compare empirically time complexities of Insertion sort vs. Merge sort.
To do so, after coding these two algorithms, you will need to calculate the time
complexities of the two algorithms for different values of n and plot the obtained complexity values.
The time complexities will be approximated only by counting the numbers of tests
(like: if ( A [ i ] > 1), and simple instructions (like: A [ i ] = A [ i − 1] + 1).
To draw plots, you will need to calculate time complexities for different values of n .
For this consider the following ones: 5, 10, 15, ... , 90, 95, 100.
For each of these values, you will need to generate an array of random integer values
Between 0 and 1000, which size is equal to the value of n .
To avoid the effect of sampling, for every array size n , you will need to repeat the
Calculations for 10 different arrays. The time complexity for every array size n , will then
be calculated as the average of the ten individual complexity values.
1.2 Required Work 1
1. Provide the code for both algorithms and show your counters are used for calculating time complexity.
2. Plot the time complexity graphs for both algorithms on the same figure.
3. What is the biggest value of n after which merge sort is better than insertion sort?
Step by Step Solution
3.36 Rating (146 Votes )
There are 3 Steps involved in it
Step: 1
Answer 11 Code for both algorithms is as f...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started