Question: Recall the Insertion - Sort algorithm discussed in the lecture: In the lecture, you have seen a correctness proof of the algorithm based on the

Recall the Insertion-Sort algorithm discussed in the lecture:
In the lecture, you have seen a correctness proof of the algorithm based on the following loop invariant
for the (outer) for loop:
Let Aj[1,dots,n] denote the array at the beginning of iteration j(end of iteration j-1). We have that
Aj[1,dots,j-1] stores the same values as A[1,dots,j-1] but in sorted order, while Aj[l]=A[l]
for jln.
In this problem, you will fill in a bit more detail in the proof, by also introducing a loop invariant for the
(inner) while loop. You will use the following loop invariant:
Let Aj,i[1,dots,n] denote the array at the beginning of iteration i of the inner loop (for 0ij-1).
Then:
If the loop executes with value i+1, then
Aj,i[1,dots,i]=Aj[1,dots,i], and
If i+2j, then Aj,i[i+2,dots,j]=Aj[i+1,dots,j-1] and i+1Aj,i=Aj,i+1ii=j-1ij1jnAj[j].
Otherwise (if the while loop terminates before reaching value i+1), then Aj,i=Aj,i+1.
Solve the following tasks:
Prove the while loop invariant above using induction over i. Start your base case ati=j-1 and
use backwards induction to show that the claim holds for all smaller i.(Prove this for an arbitrary
value ofj, where 1jn.)
Use the inner loop invariant to show the induction step of the outer loop invariant.
Recall the Insertion - Sort algorithm discussed

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!