0% found this document useful (0 votes)
492 views2 pages

Binary Search by Riddhi Dutta

This document provides a summary of different types of binary search problems and patterns. It includes 5 types of binary search problems: 1) standard and some non-standard binary search problems, 2) understanding lower and upper bounds, 3) finding pivots in rotated or mountain arrays before searching, 4) binary search on row-wise sorted matrices, and 5) minimizing or maximizing objectives. It also provides example problems and links for each type and some tips for implementing binary search.

Uploaded by

sachit dhamija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
492 views2 pages

Binary Search by Riddhi Dutta

This document provides a summary of different types of binary search problems and patterns. It includes 5 types of binary search problems: 1) standard and some non-standard binary search problems, 2) understanding lower and upper bounds, 3) finding pivots in rotated or mountain arrays before searching, 4) binary search on row-wise sorted matrices, and 5) minimizing or maximizing objectives. It also provides example problems and links for each type and some tips for implementing binary search.

Uploaded by

sachit dhamija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problems on Binary Search & Patterns

( by RIDDHI DUTTA )
Connect with me on Instagram.
Connect with me on Linkedin.
Subscribe to my Youtube Channel

For more such technical content.

Type 1 (Some ad-hoc Binary Search Problems)


- https://www.geeksforgeeks.org/order-agnostic-binary-search/
- https://leetcode.com/problems/search-insert-position/
- https://leetcode.com/problems/search-a-2d-matrix/
- https://leetcode.com/problems/sqrtx/
- https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ (IMP)
- https://leetcode.com/problems/two-sum-less-than-k/
- https://www.geeksforgeeks.org/count-numbers-difference-number-digit-sum-great
er-specific-value/ (Google Question)
- https://leetcode.com/problems/median-of-two-sorted-arrays/ (HARD)

Type 2 (Understanding Lower Bound and Upper Bound)


- Implement lower_bound and upper_bound functions of C++ on your own.
- https://leetcode.com/problems/first-bad-version/
- https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
- https://www.geeksforgeeks.org/ceiling-in-a-sorted-array/
- https://leetcode.com/problems/h-index-ii/

Type 3 (Find the pivot first , and then search)

N.B - Whenever there is a rotated or a mountain array and we need to search in that array. First
find the inflection point i.e the peak element in case of mountain array or min element or pivot in
case of rotated array. This makes our search much easier though we have to do two binary
searches.

- https://leetcode.com/problems/find-peak-element/
- https://leetcode.com/problems/find-in-mountain-array/
- https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ (Also similar to
finding the pivot point where the array was rotated)
- https://leetcode.com/problems/search-in-rotated-sorted-array/

Type 4 (Binary Search on a row wise sorted Matrix)

- https://leetcode.com/problems/search-a-2d-matrix-ii/
- https://www.geeksforgeeks.org/find-median-row-wise-sorted-matrix/

Type 5 (Minimizing the Maximum or maximizing the minimum)


(Doesn’t directly look like a binary search problem)

- https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/
- https://leetcode.com/problems/split-array-largest-sum/
- https://leetcode.com/problems/divide-chocolate/
- https://www.interviewbit.com/problems/painters-partition-problem/
- https://practice.geeksforgeeks.org/problems/allocate-minimum-number-of-pages0937/1/
- https://www.spoj.com/problems/AGGRCOW/
- https://leetcode.com/problems/minimize-max-distance-to-gas-station/

Some things to remember


- While finding mid , always use , lo + (hi - lo) / 2 , and not (hi + lo) / 2
- Normally Binary Search is done on Arrays , and not LinkedLists.
- Be careful of TLE. (if your implementation is faulty)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy