Question: Recall the Insertion - Sort algorithm InSERTION - Sort ( A , n ) for j = 2 to n key = A [ j
Recall the InsertionSort algorithm
InSERTIONSort
for to
key
while and key
key
You have seen a correctness proof of the algorithm based on the following loop invariant for the outer for loop:
Let dots, denote the array at the beginning of iteration end of iteration We have that dots, stores the same values as dots, but in sorted order, while for
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 dots, denote the array at the beginning of iteration of the inner loop for Then:
If the loop executes with value then
dots,dots, and
If then dots,dots, and
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
