What is Binary Search? Algorithm, Steps, and Time Complexity Explained

Introduction

Searching is one of the most common operations in computer science. While linear search checks every element, Binary Search provides a much faster way to find an element in a sorted list.


What is Binary Search?

Binary Search is an efficient algorithm used to find an element in a sorted array by repeatedly dividing the search space in half.


How Binary Search Works

  1. Find the middle element
  2. Compare with target
  3. If equal → found
  4. If smaller → search left
  5. If larger → search right

Example

Array: [10, 20, 30, 40, 50]
Search: 30 → Found at middle


Time Complexity

  • Best Case: O(1)
  • Worst Case: O(log n)

Applications

  • Searching in databases
  • Competitive programming
  • Large datasets

Conclusion

Binary Search is one of the fastest searching techniques but requires sorted data.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top