logo CodeStepByStep logo


Language/Type: C++ merge sort sorting
Related Links:

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};

vector<int> v2 {15, 56, 24,  5, 39, -4, 27, 10};
selection sort runtime
merge sort runtime

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.