Ask Question

Prove the correctness of Binary Search through the use of a loop invariant (which you should prove by induction). Assume that a is sorted, and that n is the number of elements in a. int BinarySearch (int * a, int n, int x) { int L = 0, r = n-1; while (L < = r) { int m = (L+r) / 2; if (a[m] = = x) return m; if (a[m] < x) L = m+1; else r = m-1; } return - 1; }

+4
Answers (1)
  1. 14 September, 12:15
    0
    Answer:i think the answer is l=

    0
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Prove the correctness of Binary Search through the use of a loop invariant (which you should prove by induction). Assume that a is sorted, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers