This repository contains a collection of 42 classic binary search problems and 8 common binary search patterns that can be used to solve them. The problems are sourced from LeetCode, and are curated to cover a range of difficulty levels such as Easy, Medium and Hard.
- What is Binary Search?
- Common Binary Search Patterns
- Classic Binary Search Problems
- License
Binary search is an algorithmic technique that allows efficient searching in sorted arrays or ranges. It works by repeatedly dividing the search interval in half until the target value is found or determined to be not in the array.
Binary search has a time complexity of O(log n), making it significantly faster than linear search for large arrays. It is a fundamental algorithm in computer science and is used in a variety of applications, including search engines, compilers, and databases.
The 8 common binary search patterns provide a framework for approaching and solving binary search problems. They are:
- Basic Binary Search
- Find First Occurrence
- Find Last Occurrence
- Find Smallest Element Greater Than Target
- Find Largest Element Smaller Than Target
- Find First Element Equal to Target
- Find Last Element Equal to Target
- Matrix Binary Search
Each pattern is explained in detail and illustrated with examples in the repository.
The 42 classic binary search problems cover a range of topics and difficulty levels, including:
S. No. | Problem Name | Problem No. | Problem Link | Problem Level | Solution Folder |
---|---|---|---|---|---|
1 | Binary Search | 704 | Link | Easy | Solution |
2 | Search Insert Position | 35 | Link | Easy | Solution |
3 | Find Smallest Letter Greater Than Target | 744 | Link | Easy | Solution |
4 | Count Negative Numbers in a Sorted Matrix | 1351 | Link | Easy | Solution |
5 | Find First and Last Position of Element in Sorted Array | 34 | Link | Medium | Solution |
This repository is licensed under the MIT License. See the LICENSE file for more information.