Sunawin A.

asked • 01/20/22

Work out the O() running time for the following recursive function. Show all your working.

void sort(int vals[], int n)

{

if (n == 1)

return;

sort(vals, n-1); // sort first n-1 values

// now insert vals[n-1] into correct position in vals[]

int temp = vals[n-1];

int i = n-1;

while ((i > 0) && (vals[i-1] > temp)) {

vals[i] = vals[i-1]; i--;

}

vals[i] = temp;

}

1 Expert Answer

By:

Chris T. answered • 02/11/22

Tutor
0 (0)

Senior Engineer @ Google | Former TA in operating systems

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.