markdown
Fundamentals of Computational Complexitymd 76c3ed3
lecture/information/algorithm/foundation/computational-complexity-basics.lecture.n.md
Download PDF

Fundamentals of Computational Complexity

date2026-07-14document_iddoc_4f15851d03885718cae9cc76d1608a96description入力サイズに対する時間・空間計算量と、O・Theta・Omega記法の相違を日英両言語で説明する。prerequisitesfor 文の反復 / 対数の基本 / 一次式と二次式type講義statusactiverelateddata/lecture/information/algorithm/algorithms-portal.lecture.n.md / data/lecture/information/algorithm/search/linear-search.lecture.n.md / data/lecture/information/algorithm/search/binary-search.lecture.n.md
algorithmfoundationundergraduatelecture

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} n 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 n.
  • {Worst-case complexity} is the maximum resource use among inputs of size n.
  • {Average-case complexity} is the expected resource use under a specified probability distribution on inputs of size n.

Average-case complexity is undefined until the probability distribution is specified. Moreover, best, average, and worst cases classify inputs, whereas O, Θ, and Ω describe asymptotic relations between functions. These are separate concepts.

4Asymptotic Notation

Let f(n) and g(n) be nonnegative for all sufficiently large n.

  • f(n)=O(g(n)) means that positive constants c,n0 exist such that f(n)[PARSE ERROR: Undefined("Command(\"le\")")]cg(n) for every n[PARSE ERROR: Undefined("Command(\"ge\")")]n0. It states an asymptotic upper bound.
  • f(n)=Ω(g(n)) means that positive constants c,n0 exist such that cg(n)[PARSE ERROR: Undefined("Command(\"le\")")]f(n) for every n[PARSE ERROR: Undefined("Command(\"ge\")")]n0. It states an asymptotic lower bound.
  • f(n)=Θ(g(n)) means that both f(n)=O(g(n)) and f(n)=Ω(g(n)) hold. It states equality of asymptotic growth rates up to constant factors.

Thus, O denotes an upper bound and does not necessarily assert a tight growth rate. For example, 3n+5=O(n2) is true, but 3n+5=Θ(n) is more precise.

5Examples

Let T(n)=3n+5. For n[PARSE ERROR: Undefined("Command(\"ge\")")]1,

3n[PARSE ERROR: Undefined("Command(\"le\")")]T(n)[PARSE ERROR: Undefined("Command(\"le\")")]8n,

so T(n)=Θ(n). Constant terms and constant factors do not alter the asymptotic growth rate.

For linear search on an array of length n, a match at the first element gives a best-case running time of Θ(1), while a match only at the final element or no match gives a worst-case running time of Θ(n). By contrast, binary search on a sorted array halves the candidate interval at each comparison. After k comparisons, at most n/2k candidates remain, yielding a worst-case running time of Θ(log(n+1)), including the empty-array case.

An algorithm that only reads its input and uses a fixed number of variables has auxiliary-space complexity Θ(1). Allocating another array of length n requires Θ(n) 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.md

7Summary

  • 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; O, Θ, and Ω describe asymptotic relations between functions.
  • O gives an upper bound, Ω gives a lower bound, and Θ gives a matching upper and lower bound.
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる