Question: The python function below takes a value and inserts it into an already sorted array ( A ) : def insert _ into _ sorted
The python function below takes a value and inserts it
into an already sorted array A:
def insertintosortedA value:
return A
Answer the following questions:
a Complete the function using python or a different language if you prefer
b Run your program for several different input values. Does your method
appear to work for both standard input and edge cases eg empty arrays,
duplicate values, etc... Why do you believe this?
c Describe a loop invariant that will help you prove correctness.
d Prove that your algorithm is correct by showing that the loop invariant
remains true during initialization, maintenance, and termination
e How does this relate to the correctness of the insertion sort? Hint: How
would you modify insertion sort to use your method?
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
