Question: (a) Find the proper loop invariant for the while-loop (Inv (p1, p2, p3) ) so that it is sufficient for proving the cor- rectness of

 (a) Find the proper loop invariant for the while-loop (Inv (p1,p2, p3) ) so that it is sufficient for proving the cor-

(a) Find the proper loop invariant for the while-loop (Inv (p1, p2, p3) ) so that it is sufficient for proving the cor- rectness of SortABC. (b) Prove the invariant that your find in (a), using induction. Hint: The proof of the invariant could be divided into different cases of the processed part of the array - try to divide the cases in a simple way (i.e., keep the number of possible cases relatively small) and make sure to analyse all possible cases thoroughly. (c) Use the invariant to prove that the postcondition of SortABC is satisfied if the loop terminates. (d) Prove that the loop must terminate after a finite number of iterations.1. [10] Consider the following program which sorts a list that only contains letters A, B or C. For example, the input list [B, A, A, C, A, B] is sorted into [A, A, A, B, B, C], and the input [A, C, A, C] is sorted into [A, A, C, C]. / / Pre: is non-empty and contains only 'A', 'B', or 'C'. / / Post: is sorted in non-descending order, alphabetically. void SortABC (char Ist) { int p1 = 0; int p2 = 0 ; int p3 = 0; while (p3

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 Programming Questions!