As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. Maurice Wilkes
Binary search is a method to find the particular item in sorted array. In each step, the algorithm divides the array equally and match the middle item. If the key match, return the index. If key is less then middle, search left subarray. Else search right subarray.
Binary search uses divide and conquer strategy to search the item from the sorted array. The binary search eliminate half of the elements for each iteration. It requires sorted array and will not work for a un-sorted array like linear search.
The binary search algorithm can be implemented using the iterative method and recursive method. Write a program to implement Binary Search?
Before Sort: [12, 55, 45, 11, 23, 20, 17, 24, 9] After Sort: [9, 11, 12, 17, 20, 23, 24, 45, 55] Found in 2 Position!