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/4_Silver/4_Silver_BinSearch.md
2020-06-09 00:01:24 -04:00

2.9 KiB

slug title author order prerequisites
/silver/binary-search Binary Search Nathan Chen 4
Silver - Sorting

Binary search can be used on monotonic functions for a logarithmic runtime.

Basic Application

Here is a very basic form of binary search:

Find an element in a sorted array of size N in O(\log N) time.

Other variations are similar, such as the following:

Given K, find the largest element less than K in a sorted array.

Tutorial

Java

C++

Problems

Binary Searching on the Answer

Oftentimes used when you need to find the minimum or maximum of some quantity such that it satisfies some property.

Tutorial

  • Intro to USACO 12.1

Problems