This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/2_Silver/4_Silver_BinSearch.md
2020-06-05 19:04:47 -04:00

35 lines
1.3 KiB
Markdown

---
slug: /silver/binary-search
title: "Binary Search"
author: Nathan Chen
order: 4
prerequisites:
-
- Silver - Sorting
---
Binary search can be used on monotonic functions for a logarithmic runtime.
<!-- END DESCRIPTION -->
## The Basic Application
Find an element in a sorted array in O(log N) time.
### Tutorial
- [GeeksForGeeks](https://www.geeksforgeeks.org/binary-search/)
- [Wikipedia](https://en.wikipedia.org/wiki/Binary_search_algorithm)
### Problems
- [USACO Silver Counting Haybales](http://www.usaco.org/index.php?page=viewproblem2&cpid=666)
## Binary Searching on the Answer
Oftentimes used when you need to find the "minimum" or "maximum" of some quantity that satisfies a property.
### Tutorial
- [CPH Section 12.1](https://www.overleaf.com/project/5e73f65cde1d010001224d8a)
### Problems
- [USACO Silver Cownvention](http://www.usaco.org/index.php?page=viewproblem2&cpid=858)
- [USACO Silver Cow Dance](http://www.usaco.org/index.php?page=viewproblem2&cpid=690)
- [USACO Silver Social Distancing](http://www.usaco.org/index.php?page=viewproblem2&cpid=1038)
- [USACO Silver Loan Repayment](http://www.usaco.org/index.php?page=viewproblem2&cpid=991)
- Also needs some math and "sqrt" analysis
- [USACO Silver Angry Cows](http://usaco.org/index.php?page=viewproblem2&cpid=594)