EmbLogic's Blog

BINARY SEARCH……..

  1. Binary search technique works for the sorted list.
  2. It is one of the most efficient techniques of searching.
  3. It is a technique of searching in ordered list where we first find middle value.
  4. Based on the comparison between the middle value and key vaue(to be searched) half of the data is discarded.
  5. Most of the dictionary apps uses this techique.
  6. 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

  1. key->value to be searched.
  2. n->number of elements.
  3. array->list of elements.

STEPS:

  1. 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 !!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>