Binary Search Algorithm Using Python


def binarySearch(array,target):
  start=0
  end=len(array)
  while start<end:
    mid=start+(end-start)/2
    val=array[mid]
    if target==val:
      return mid
    elif target>val:
      if start==mid:
        break
      start=mid+1
    elif target
      end=mid-1

print binarySearch([2,4,6,7,3,10],3)

Advertisements

Software Engineer at The Jaxara IT Ltd , Dhaka , Bangladesh

Tagged with: ,
Posted in Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: