Suppose we are doing selection and merge sorts on the vector below, and that we are operating on a computer where essentially every operation is cost-free (takes 0 time to execute) except for the act of assigning a value into a slot of the vector passed in (such as setting V1[0] = 42;
), which requires 100 units of time. (Assigning a value to a normal int variable, or into any other vector or collection, requires no time in this hypothetical model.) How long does each algorithm take to run for this particular data under these particular conditions? Which sorting algorithm requires less time to run? Assume that selection does not perform a swap if not necessary, that is, if the two indexes of interest are the same.
// index 0 1 2 3 4 5 6 7
vector<int> v1 {15, 56, 24, 5, 39, -4, 27, 10};
selectionSort(v1);
vector<int> v2 {15, 56, 24, 5, 39, -4, 27, 10};
mergeSort(v2);