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

पुढे वाचा

Algorithm: Insertion Sort

Algorithm: Selection Sort

Algorithm: Bubble Sort

Algorithm: Binary Search

Algorithm and flowchart to Search a particular data from the given Array of numbers using: Linear Search Method.

Leave a comment