Binary Search (Flowchart)

This flowchart illustrates the binary search algorithm - an efficient method for finding a target value in a sorted array. The diagram demonstrates the process of repeatedly dividing the search interval in half, comparing the target with the middle element, and adjusting the search boundaries accordingly.

Binary search is an efficient algorithm used to find the position of a target value within a sorted array. Its purpose is to reduce the search space by half with each comparison, leading to a time complexity of 𝑂(log⁡𝑛), which is much faster than linear search for large datasets.

Binary Search Flowchart

Binary Search Flowchart
Binary Search Flowchart

Binary Search Algorithm

  • Initialize:
    • Set left to 0 (the first index of the array).
    • Set right to the last index of the array.
  • Loop:
    • While left is less than or equal to right:
    • Calculate the middle index mid as the floor value of (left + right) / 2.
    • Compare the target value with the value at mid:
      • If they are equal, return mid (the index of the target).
      • If the target is greater than the value at mid, set left to mid + 1 (search in the right half).
      • If the target is less than the value at mid, set right to mid - 1 (search in the left half).
  • End Loop:
    • If the target is not found, return -1.

Download the flowchart with the binary search algorithm. You can open and edit it using our flowchart maker.

Binary Search (Flowchart)

New Comment

Comment