Algorithm: Binary Search
Goal: Search for a given element (key) in a sorted array using Binary Search.
Steps:
Start
Input n (number of elements in the array).
Input the sorted array arr[0…n-1].
Input key (element to be searched).
Set low = 0, high = n - 1.
Repeat whilelow <= high:
Set mid = (low + high) / 2.
If arr[mid] == key:
Print “Element found at position mid”.
Stop.
Else If arr[mid] < key:
Set low = mid + 1.
Else:
Set high = mid - 1.
If loop ends without finding the element: Print “Element not found”.
Stop.
Flowchart: Binary Search

Post Comment