Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Explain the key components of an assessment center (AC).

Answered: 1 week ago