2. Introduction
Binary Search is a search algorithm that
finds the position of a target value within a
sorted array.
Binary Search is also known as half-
interval search or logarithmic search.
Binary Search algorithm works on the
principle of Divide And Conquer.
Binary Search can be implemented on only
sorted list of elements.
3. Divide And Conquer
Divide and Conquer is the most-well known
algorithm strategy.
A Divide and Conquer algorithm works by
recursively breaking down a problem into
two or more sub-problems of the same or
related type, until these become simple
enough to be solved directly.
The solutions to the sub-problems are then
combined to give a solution to the original
problem.
4. Example
Consider an Array:
A
0 1 2 3 4 5 6 7 8
min mid=(min + max)/2 max
If(37==a[mid]) return mid
Else if(37<a[mid]) max=mid-1
Else if(37>a[mid]) min=mid+1
20 35 37 40 45 50 51 55 67
5. Algorithm
Input :
A ← sorted array
n ← size of array
key← value to be searched
BinarySearch(a,key,n) :
Set min= 0
Set max= n-1
while (min < max)
Set mid=(min + max)/2
7. Time Complexity
The running time complexity for Binary Search
are of three types :-
In Worst Case ,Time Complexity : O(log n)
In Average Case ,Time Complexity : O(log n)
In Best Case , Time Complexity : O(1)
8. Advantage
Binary Search is an optimal searching
algorithm using which we can desired
element very efficiently.
10. Application
The Binary Search is an efficient searching
method and used to search desired record
from database.
For solving non-linear equations with one
unknown this method is used.