Pseudocode for Binary Search


What is Binary Search Algorithm?

Binary Search is the most famous and simplest Searching Algorithm that searches the given list for a target element. But the only condition is that the given list should be sorted, only then you can use Binary Search for searching.

Simple Binary Search Algorithm

Binary Search Pseudocode:

Step 1: Start Step 2: Input Sorted array in "a[]" and element to be searched in "x" and size of array in "size" Step 3: Initialize low=0, high=size-1 Step 4: Repeat until low>=high Step 4.1: mid=(low+high)/2 Step 4.2: If a[mid] is equal to x, then, print index value of mid and Goto step 6 Else If a[mid]<x low=mid+1 else high=mid-1 Step 5: Print x not found in the list Stop 6: Stop

Binary Search Algorithm Explanation:

Binary search compares the search element to the middle element of the list. If the search element is greater than the middle element, then the left half or elements before the middle elements of the list is eliminated from the search space, and the search continues in the remaining right half. Else if the search element is less than the middle value, the right half or all elements after the middle element is eliminated from the search space, and the search continues in the left half. This process is repeated until the middle element is equal to the search element, or if the algorithm finds that the searched element is not in the given list at all.

Similar Posts:

  1. Binary Search Algorithm Program in C
  2. Algorithm for Sequential Search or Linear Search

Solution Worked 7 UpvotesUpvote


Solution Didn't Worked 1 DownvotesDownvote