Searching is an important operation in every-day life and even in many software applications, as we frequently search for data!
Searching is a method to find some relevant information in a data set
Searching
Lets try to search for Number 12.
1 3 4 5 9 12 22 38 45
Can we do better? Can we exploit the information that array is sorted?
Binary Search is an algorithm that can be used to search an element in a sorted data set.
Binary Search
By sorted, we mean that the elements will either be in a natural increasing or decreasing order.
Lets try to search for Number 12.
1 3 4 5 9 12 22 38 45
What is the number doesn't exist? Lets try to search for 6.
1 3 4 5 9 12 22 38 45
Binary Search is a Divide & Conquer Algorithm.
Binary Search
It divides the array into two halves and tries to find the element K in one or the other half, not both. It keeps on doing this until we either find the element or the array is exhausted.