43 (11B)
43 (11B)
Date:
AIM
To write a C program to perform Binary Search operation
ALGORITHM
6. If not, check if the search element is smaller or larger than the middle element.
7. If smaller, repeat for the left sublist; if larger, repeat for the right sublist.
8. Continue until the element is found or the sublist has only one element.
PROGRAM
#include <stdio.h>
void main()
{
int a[10], i, n, item, flag = 0, low, high, mid;
// If item is found
if (item == a[mid])
{
flag = 1;
break;
}
// If item is smaller than the middle element, search in the left half
else if (item < a[mid])
{
high = mid - 1;
}
// If item is larger, search in the right half
else
{
low = mid + 1;
}
}
RESULT
Thus the program to perform binary search operation was executed successfully