PROJECTENGRAM

TIME COMPLEXITY

Time Complexity

Tags: #◇CCDSALG #◇Algorithms #◇Computer Science #◇Computational Complexity #◇Efficiency #◇Algorithm Design Paradigms #◇Analysis of Algorithms #◇Data Structures #◇Time Complexity #◇Space Complexity


◇Overview

Time complexity measures the amount of computational time an algorithm takes as a function of the input size nn.

◇Key Concepts

Time complexity as a function T(n)T(n) Counting primitive operations via ◇Frequency Count Asymptotic notation to classify growth rate Best-case, worst-case, and average-case time

◇Details / Theory

Definition

Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm as a function of the length of the input. It is typically expressed using ◇Asymptotic Notation, most commonly ◇Big-O Notation.

How Time Complexity is Determined

  1. Identify the input size nn (e.g., array length, number of nodes).
  2. Count primitive operations as a function of nn using the ◇Frequency Count method.
  3. Express the total count as a mathematical function T(n)T(n).
  4. Simplify using asymptotic notation — drop constants and lower-order terms.

Common Time Complexities (Ordered by Growth)

ComplexityNameExample
O(1)O(1)ConstantArray index access
O(log⁡n)O(\log n)LogarithmicBinary Search
O(n)O(n)LinearLinear Search
O(nlog⁡n)O(n \log n)LinearithmicMerge Sort
O(n2)O(n^2)QuadraticBubble Sort
O(n3)O(n^3)CubicNaive matrix multiplication
O(2n)O(2^n)ExponentialSubset generation
O(n!)O(n!)FactorialPermutation generation

Relationship to Analysis Types

◇Worst-Case Analysis: T(n)=T(n) = maximum time over all inputs of size nn ◇Average-Case Analysis: T(n)=T(n) = expected time over all inputs of size nn ◇Best-Case Analysis: T(n)=T(n) = minimum time over all inputs of size nn

Measuring Time Complexity

We do not measure actual wall-clock time (that depends on hardware, language, etc.). Instead, we count the number of primitive/elementary operations executed. This is done via ◇A Priori Analysis using the ◇RAM Model.

◇Common Pitfalls

Confusing time complexity with actual execution time — O(n2)O(n^2) doesn't mean "slow," it describes the growth rate. Forgetting that Big-O drops constants: O(2n)O(2n) is just O(n)O(n). Ignoring the difference between best, worst, and average case.

◇Summary

TL;DR — Time complexity measures how an algorithm's running time scales with input size nn, expressed using asymptotic notation (commonly Big-O). It is determined by counting primitive operations via frequency count analysis.

Related: ◇Running Time — ◇Space Complexity — ◇Frequency Count — ◇Asymptotic Notation — ◇Big-O Notation — ◇Growth Rates — ◇Worst-Case Analysis — ◇Average-Case Analysis — ◇Best-Case Analysis Source / Reference: Handout 01, Handout 02

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

What does time complexity measure?

Q2

How are primitive operations typically counted to determine time complexity?

Q3

Which notation is most commonly used to express time complexity by classifying its growth rate?

Q4

What is the time complexity of a simple array index access?

Q5

Which of the following time complexities is considered the most efficient (slowest growing)?

Q6

What does worst-case time complexity represent?

Q7

What does average-case time complexity represent?

Q8

Do we measure actual wall-clock time when determining theoretical time complexity?

Q9

What is a common pitfall regarding O(n2)O(n^2) time complexity?

Q10

Why does O(2n)O(2n) simplify to O(n)O(n)?

Time Complexity | PROJECT ENGRAM