Category Archives: Array Searching

C Program to Search for an Element in an Array Using Binary Search

There is a condition for performing binary search, the prerequisite for binary search is that the array should be sorted. Firstly we compare the item to be search with the middle element of the array, if the the item is found the search is successful otherwise the array is divided into two halves, first half contains all the elements to the left of the middle element and the other one consists of all the elements to the right side of the middle element. Since the array is sorted, all the element in the left half will be smaller than the middle element and greater than the middle element in the right half. If the item to be search is less than the middle element, it will be search in left half otherwise it will be search in the right half (if it is greater then the middle element). Let’s now see the c program to search for an element in an array using binary search.

C Program ►►
Continue reading C Program to Search for an Element in an Array Using Binary Search

Advertisements

C Program to Search an Element in an Array Using Linear or Sequential Search

Before making the C program to search an element in an array using linear search, first understand what linear search means. Sequential search or Linear search is performed in linear way i.e. it starts from the beginning of the list and continues till we find the item or reach the end of list. The item to be searched is compared with each element of the list one by one, starting from the first element.

Let’s See The Program ►►
Continue reading C Program to Search an Element in an Array Using Linear or Sequential Search