1. Engineering
  2. Computer Science
  3. please do the following exercise answer the questions following the...

Question: please do the following exercise answer the questions following the...

Question details
Please do the following exercise, answer the questions following the instructions and please justify your answer.
Exercise 4 (35 points) Loop Invariant Consider the naive sorting algorithm we presented in Module I: Sort-Array (A) for j = 1 to (A. length - 1) for i (j + 1) to A. length if (A[iAj]) // swap A[i] and Aj] buffer A Ali] buffer The objective is to prove that the above sorting algorithm is correct. Consider getting inspiration from the textbook in Section 2.1: the author shows that the Insert Sort algorithm is correct using loop invariants. This should help you with this exercise. l) (2 points) Express the property that Sort-Array (A) must satisfy to be correct: 2) (4 points) Can you find some loop invariants for the outer for loop? List these invariants (evenif they are not that helpful for our ultimate proof of correctness of Sort-Array) 3) (9 points) Propose a loop invariant for the outer loop that is the closest to our ultimate objective: Sort-Array is correct. 4) Use the three steps: a. (4 points) Initialization b. (10 points) Maintenance C. (6 points)Termination
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution