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
- Find the middle element
- Compare with target
- If equal → found
- If smaller → search left
- 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.