Question: You are given the algorithm below: 1 2 3 4 5 6 7 8 9 10 11 12 void fcn(int arr, int n) {
You are given the algorithm below: 1 2 3 4 5 6 7 8 9 10 11 12 void fcn(int arr, int n) { int h, i, j, t; for (h= n; h /= 2; ) { } for (i =h; i < n; ++i) { t = arr [i]; for (ji; j >= h&& tarr[j - h]; j - h) { = arr [j] arr [j- h]; } arr [j] = t; (a) What is the algorithm doing? (b) Determine the loop invariants of each for-loop. (c) Prove the correctness of each loop invariant. (d) Determine the worst-case time complexity and auxiliary space complexity of the algorithm.
Step by Step Solution
3.53 Rating (146 Votes )
There are 3 Steps involved in it
Answer Lets analyze the given algorithm void fcnint arr int n int h i j t for h n h 2 for i h i n i t arri for j i j h t arrj h j h arrj arrj h arrj t ... View full answer
Get step-by-step solutions from verified subject matter experts
