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 is the maximum time taken by an algorithm on any input of size .
◇Key Concepts
Formal expression: 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:
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
- Guarantee: Gives an upper bound on execution time — the algorithm will never take longer.
- No probability assumptions: Unlike ◇Average-Case Analysis, no distribution over inputs is needed.
- Simplicity: Typically easier to analyze than average-case.
- Safety: Critical for real-time and safety-critical applications.
Expressing Worst-Case Running Time
Usually expressed using ◇Big-O Notation: e.g., . For a tight bound, ◇Big-Theta Notation is preferred: . The actual function may be something like , but we care about the ◇Order of Growth.
Examples
| Algorithm | Worst-Case Running Time | Worst Input |
|---|---|---|
| Linear Search | Element not in array | |
| Binary Search | Element not in array | |
| Bubble Sort | Reverse-sorted array | |
| Merge Sort | Any input (always same) | |
| Quick Sort | Sorted array with bad pivot |
[!tip] Key Insight
Merge Sort has the same worst-case and best-case running time (), while Quick Sort’s worst-case () is much worse than its average-case ().
◇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 . It’s the default analysis metric because it provides guaranteed performance bounds.
◇Links
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
- Previous Topic: ◇Worst-Case Analysis
- Next Topic: ◇Reccurences
- Related Notes: ◇Worst-Case Analysis, ◇Running Time
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
How is worst-case running time mathematically defined?
Why is worst-case running time the default metric in Algorithm Analysis?
If we want a TIGHT bound on the worst-case running time, which notation is preferred?
What is the worst-case running time of Binary Search?
Which of the following statements about Merge Sort is true?
In Quick Sort, how does the worst-case running time compare to the average-case?
What is a common pitfall regarding the best, worst, and average cases of an algorithm?
What is a common pitfall regarding the scope of worst-case running time?
What is the worst-case input for Linear Search?
Why might actual running time formulas like be abstracted into Big-O notation when discussing worst-case running time?