Answered step by step
Verified Expert Solution
Question
1 Approved Answer
function returned the index of the first occurrence of r in the array A, or -1 if x is not found. Now let's fill in
function returned the index of the first occurrence of r in the array A, or -1 if x is not found. Now let's fill in the loop body with code that implements the binary search algorithm (on a sorted array, of course) int search (int x, int[] A, int n) 2 //@requires = x); - + 19 20 @*/ 21 hi = mid; 23 24 //@assert lo == hi; 26 if (lo != n && A[10]-x) return 10; 2 return -1; 28 Prove that, in the case that the code returns on line 18, the postcondition on lines 4-7 always evaluates to true. We've given the starting facts you'll use in this proof. Justify your answers using line numbers or previous steps When we start an iteration of the loop, we know the following: (a) = x); - + 19 20 @*/ 21 hi = mid; 23 24 //@assert lo == hi; 26 if (lo != n && A[10]-x) return 10; 2 return -1; 28 Prove that, in the case that the code returns on line 18, the postcondition on lines 4-7 always evaluates to true. We've given the starting facts you'll use in this proof. Justify your answers using line numbers or previous steps When we start an iteration of the loop, we know the following: (a)
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