- Binary search technique works for the sorted list.
- It is one of the most efficient techniques of searching.
- It is a technique of searching in ordered list where we first find middle value.
- Based on the comparison between the middle value and key vaue(to be searched) half of the data is discarded.
- Most of the dictionary apps uses this techique.
- It is costly to do linear search to find information on internet,so here also binary seach technique is used.
ALGORITHM:
- B_search(key,n,array)
where
- key->value to be searched.
- n->number of elements.
- array->list of elements.
STEPS:
- Initialize
low=1; high=n; flag=0;
2.Repeat 3&4
3.while(low<high)
mid=(low+high)/2
4.if(key<array[mid])
then high=mid-1
elseif (key>array[mid])
then low=mid+1;
elseif (key==array[mid])
then flag=1 & search successful;;;;;
5. if(flag!=1) ERROR !!!!!