Description
What is Binary Search ?
Presentation Transcript
Binary Search : Binary Search This method is applicable only when the list or the array is sorted i.e. when
the array is arranged in ascending or descending order. Binary means two
Therefore, in binary search method, the data is searched by dividing the list or
array into two groups. First the data to be searched is compared with the
middle item of the list. If a match is found then the search is over otherwise the
array is divided into two halves and checked in which half port ( upper / lower)
of the array is the data present. i.e. in the upper half of the list or in the lower
half of the list. In case, the array is arranged in descending order and the data
is greater than the middle item , then it means the data lies in the upper half of
the list, other wise the data is in the lower half of the list.
a) If the data lies in the upper half of the list, then the data is compared with the
middle item of the upper half of the list. If a match is found then the search is
over, otherwise the process (i.e. dividing the resultant list into two halves,
determining in which half the data is lying, and comparing the data with the
middle item of the resultant list ) is continued till the list gets over.
b) If the data lies in the lower half of the list then the data is compared with the
middle item of the lower half of the list . If a match is found then the search is
over, otherwise the process (i.e. dividing the resultant list into two halves,
determining in which half the data is lying, and comparing the data with the
middle item of the resultant list ) is continued till the list gets over. At any step
if a match is found then the search gets over there itself. But if no match is
found till the list is left with a single element, then it means the data is not
present in the list.
Your Facebook Friends on WizIQ