Programming Examples
Algorithm for Binary Search
1. Accept the element to be searched.
2. Set lowerbound = 0.
3. Set upperbound = n – 1.
4. Set mid = (lowerbound + upperbound)/2.
5. If arr[mid] = desired element:
a. Display "Found".
b. Go to step 10.
6. If desired element < arr[mid]:
Set upperbound = mid – 1.
7. If desired element > arr[mid]:
Set lowerbound = mid + 1.
8. If lowerbound <= upperbound:
Go to step 4.
9. Display "Not Found".
10. Exit.
Output