Question
The following is a pseudocode of Insertion-sort. Prove its correctness via loop invariant. In other words, state the loop invariant and prove it using Initialization/Basecase,
The following is a pseudocode of Insertion-sort. Prove its correctness via loop invariant. In other words, state the loop invariant and prove it using Initialization/Basecase, Maintenance/Inductive Step, and Termination/Conclusion. The following is a pseudo-code of Selection-Sort. We would like to prove its correctness via loop invariant. State a loop invariant. Note that your loop invariant must be strong enough to lead to the correctness of the algorithm. You only need to state the loop invariant. (No need to show Initialization, Maintenance, or Termination.) Prove that the Merge-Sort pseudocode shown in Question 5 is correct. That is, prove that Merge-Sort(A, p, r) sorts the subarray A[p...r] in increasing order. You can assume that Merge(A, p, q, r) successfully merges two sorted arrays, A[p...q] and A[q+ 1...r], into a sorted array A[p...r]. Please do not forget the basecase.
8. (20 points) The following is a pseudocode of Insertion-sort. Prove its correctness via loop invariant. In other words, state the loop invariant and prove it using Initialization/Base case, Maintenance/Inductive Step, and Termination/Conclusion. Insertion-Sort(A) 1. for j = 2 to A.length 2. key = A[j] 3. // Insert A[j] into the sorted sequence A[1... j - 1]. 4. i = j - 1 while i > 0 and A[i] > key 6. A[i + 1] A[i] i = i 1 Ai + 1] key 5. 1. 8. 9. (10 points) The following is a pseudo-code of Selection-Sort. We would like to prove its correctness via loop invariant. State a loop invariant. Note that your loop invariant must be strong enough to lead to the correctness of the algorithm. You only need to state the loop invariant. (No need to show Initialization, Maintenance, or Termination.) 3. Selection-Sort (A) 1. n = A.length 2. for j = 1 to n-1 smallest j 4. for i j+1 to n 5. if A[i]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started