1. Engineering
  2. Computer Science
  3. write a proof by induction to show the correctness of...

Question: write a proof by induction to show the correctness of...

Question details

2. Write a proof by induction to show the correctness of the binary search code given below: /1 Find index of x in sorted array A[p..r]. Return -1 if x is not in A[p..r]. int binarySearch ( A, p, r, x) Pre: A[p..r] is sorted if p>r then return -1 else q (p+r)/2 if x <AIq] then else if xA[q] then else // x A[q] return binarySearch A, p, q-1, x) return q return binarySearch ( A, q+1, r, x)

Write a proof by induction to show the correctness of the binary search code given below:

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution