Question: 9. Give the pre- and postconditions for a program that takes as an input an array of size n in which each item in the

9. Give the pre- and postconditions for a program that takes as an input an array of size n in which each item in the array is an integer and the items are sorted in decreasing order starting at position 0 of the array. The number of items in the array before the program begins is S. The program inserts a new item into the array if there is room. The return value is S + 1 if the item was inserted or -1 if not. (You do not need to write the program) {. precondition } int insert(int A[], int s, int item) { postcondition Let s' equal the return value } 10. Give the loop invariant assertion for the program sequential search. } {. n > 0 and A[0] > A[1] > . > A[n-1] int sequential Search(int A[], int key) int i = 0; int position = -1; while (i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
