Let See How the Binary Search is Working

Let See How the Binary Search is Working

First Condition is ,array  should be soted

Find length of array ,here it is 5 and mid 2 at index 2 = 3

we have to find key = 2 element in array

but the middle element is greater than key so

we have to find the key in left side of middle element

so , we will consider ,search in left side and again start 

find mid and check  mid==key  if yes we find it !

at index 1 key==arr[1] we find key  done ! algo

if You want c++ | Java | Python | Implementation read full article below..