PROJECTENGRAM

WORST-CASE RUNNING TIME

Worst-case running time

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


◇Overview

The worst-case running time T(n)T(n) is the maximum time taken by an algorithm on any input of size nn.

◇Key Concepts

Formal expression: T(n)=max⁡{T(I):∣I∣=n}T(n) = \max\{T(I) : |I| = n\} Why it is the default performance metric Connection to ◇Big-O Notation and ◇Worst-Case Analysis Distinguished from average-case and best-case running time

◇Details / Theory

Definition

The worst-case running time is the function:
T(n)=max⁡all inputs I of size nT(I)T(n) = \max_{\text{all inputs } I \text{ of size } n} T(I)

It represents the longest possible execution time for any input of a given size. This is the standard metric used in ◇Algorithm Analysis.

Why It Is the Default Metric

  1. Guarantee: Gives an upper bound on execution time — the algorithm will never take longer.
  2. No probability assumptions: Unlike ◇Average-Case Analysis, no distribution over inputs is needed.
  3. Simplicity: Typically easier to analyze than average-case.
  4. Safety: Critical for real-time and safety-critical applications.

Expressing Worst-Case Running Time

Usually expressed using ◇Big-O Notation: e.g., T(n)=O(n2)T(n) = O(n^2). For a tight bound, ◇Big-Theta Notation is preferred: T(n)=Θ(n2)T(n) = \Theta(n^2). The actual function may be something like T(n)=3n2+5n+2T(n) = 3n^2 + 5n + 2, but we care about the ◇Order of Growth.

Examples

AlgorithmWorst-Case Running TimeWorst Input
Linear SearchO(n)O(n)Element not in array
Binary SearchO(log⁡n)O(\log n)Element not in array
Bubble SortO(n2)O(n^2)Reverse-sorted array
Merge SortO(nlog⁡n)O(n \log n)Any input (always same)
Quick SortO(n2)O(n^2)Sorted array with bad pivot

[!tip] Key Insight
Merge Sort has the same worst-case and best-case running time (Θ(nlog⁡n)\Theta(n \log n)), while Quick Sort’s worst-case (n2n^2) is much worse than its average-case (nlog⁡nn \log n).

◇Common Pitfalls

Assuming all algorithms have different best/worst/average cases — some (like Merge Sort) are the same across all cases. Confusing the worst-case running time of an algorithm with the lower bound of a problem.

◇Summary

TL;DR — Worst-case running time is the maximum time an algorithm takes on any input of size nn. It’s the default analysis metric because it provides guaranteed performance bounds.

Related: ◇Worst-Case Analysis — ◇Running Time — ◇Time Complexity — ◇Big-O Notation — ◇Average-Case Analysis — ◇Best-Case Analysis Source / Reference: Handout 01, Page 3

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

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

Q1

How is worst-case running time mathematically defined?

Q2

Why is worst-case running time the default metric in Algorithm Analysis?

Q3

If we want a TIGHT bound on the worst-case running time, which notation is preferred?

Q4

What is the worst-case running time of Binary Search?

Q5

Which of the following statements about Merge Sort is true?

Q6

In Quick Sort, how does the worst-case running time compare to the average-case?

Q7

What is a common pitfall regarding the best, worst, and average cases of an algorithm?

Q8

What is a common pitfall regarding the scope of worst-case running time?

Q9

What is the worst-case input for Linear Search?

Q10

Why might actual running time formulas like T(n)=3n2+5n+2T(n) = 3n^2 + 5n + 2 be abstracted into Big-O notation when discussing worst-case running time?