計算量 の基本
1導入
この
2入力 サイズと計算資源
3入力 ごとの差異
は、サイズ の最良計算量 入力 における最小 の資源使用量 である。 は、サイズ の最悪計算量 入力 における最大 の資源使用量 である。 は、サイズ の平均計算量 入力集合 に確率分布 を指定 したときの資源使用量 の期待値 である。
4漸近記法
と を
- とは、ある
正 の定数 が存在 し、すべての で が成立 することである。これは漸近的上界 を表 す。 - とは、ある
正 の定数 が存在 し、すべての で が成立 することである。これは漸近的下界 を表 す。 - とは、 と の
双方 が成立 することである。これは定数倍 を除 いて漸近的増加率 が一致 することを表 す。
したがって、 は
5具体例
とする。 では
が
6後続講義 への接続
7要約
入力 サイズは、問題 に適 した尺度 によって定義 する。時間計算量 と空間計算量 は、異 なる計算資源 を評価 する。最良 ・平均 ・最悪 は入力 の区分 であり、・・ は関数間 の漸近的関係 である。- は
上界 、 は下界 、 は同一 の関数 による上界 と下界 を表 す。
Fundamentals of Computational Complexity
1Introduction
This lecture explains how to evaluate growth in running time and memory use as the input size increases. Rather than relying only on elapsed seconds measured on a particular computer, asymptotic growth permits analysis of an algorithm as inputs become large.
2Input Size and Computational Resources
The {input size} is a nonnegative integer that measures the scale of a problem instance. An appropriate measure depends on the problem: a one-dimensional array may use its number of elements, whereas a two-dimensional array may require both its numbers of rows and columns. Not every input is therefore adequately described by a single parameter.
{Time complexity} is a function describing how the number of executed basic operations grows with input size. {Space complexity} is a function describing growth in memory required during execution. When the analysis excludes storage occupied by the input itself and counts only additional storage, the measure is called {auxiliary-space complexity}.
3Variation among Inputs
Inputs of the same size can require different amounts of a resource.
- {Best-case complexity} is the minimum resource use among inputs of size .
- {Worst-case complexity} is the maximum resource use among inputs of size .
- {Average-case complexity} is the expected resource use under a specified probability distribution on inputs of size .
Average-case complexity is undefined until the probability distribution is specified. Moreover, best, average, and worst cases classify inputs, whereas , , and describe asymptotic relations between functions. These are separate concepts.
4Asymptotic Notation
Let and be nonnegative for all sufficiently large .
- means that positive constants exist such that for every . It states an asymptotic upper bound.
- means that positive constants exist such that for every . It states an asymptotic lower bound.
- means that both and hold. It states equality of asymptotic growth rates up to constant factors.
Thus, denotes an upper bound and does not necessarily assert a tight growth rate. For example, is true, but is more precise.
5Examples
Let . For ,
so . Constant terms and constant factors do not alter the asymptotic growth rate.
For linear search on an array of length , a match at the first element gives a best-case running time of , while a match only at the final element or no match gives a worst-case running time of . By contrast, binary search on a sorted array halves the candidate interval at each comparison. After comparisons, at most candidates remain, yielding a worst-case running time of , including the empty-array case.
An algorithm that only reads its input and uses a fixed number of variables has auxiliary-space complexity . Allocating another array of length requires auxiliary space. Time and space must be analyzed separately.
6Connections to Subsequent Lectures
The next lecture derives the time and auxiliary-space complexity of recursion from the number of recursive calls and the maximum call depth. The subsequent sorting and search lectures compare applicability conditions, correctness, and complexity together.
data/lecture/information/algorithm/foundation/recursion-basics.lecture.n.md7Summary
- Input size must be defined by a measure appropriate to the problem.
- Time and space complexity measure different computational resources.
- Best, average, and worst cases classify inputs; , , and describe asymptotic relations between functions.
- gives an upper bound, gives a lower bound, and gives a matching upper and lower bound.