Skip to content

This repository contains a collection of 42 classic binary search problems and 8 common binary search patterns that can be used to solve them.

License

Notifications You must be signed in to change notification settings

bhartik021/Binary-Search

Repository files navigation

Binary-Search

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.

Table of Contents

  • What is Binary Search?
  • Common Binary Search Patterns
  • Classic Binary Search Problems
  • License

What is Binary Search?

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.

Common Binary Search Patterns

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.

Classic Binary Search Problems

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

License

This repository is licensed under the MIT License. See the LICENSE file for more information.

About

This repository contains a collection of 42 classic binary search problems and 8 common binary search patterns that can be used to solve them.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages