Question: A programmer has written the following function for implementing the merge sort algorithm, but is not sure if the function is correct. void merge _

A programmer has written the following function for implementing the merge sort algorithm, but is not sure if the function is correct.
void merge_sort(vector& a, int from, int to)
{
if (from == to){ return; }
int mid =(from + to)/2;
// Sort the first and the second half
merge_sort(a, from +1, mid);
merge_sort(a, mid +1, to);
merge(a, from, mid, to);
}
What is true about this merge_sort function?
Question 10 options:
It is a recursive function that will never terminate.
The call to merge is not necessary.
There is a mistake in the parameters passed to the recursive calls to merge_sort.
The merge_sort function works perfectly as written.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!