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 .
◇Key Concepts
Time complexity as a function 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
- Identify the input size (e.g., array length, number of nodes).
- Count primitive operations as a function of using the ◇Frequency Count method.
- Express the total count as a mathematical function .
- Simplify using asymptotic notation — drop constants and lower-order terms.
Common Time Complexities (Ordered by Growth)
| Complexity | Name | Example |
|---|---|---|
| Constant | Array index access | |
| Logarithmic | Binary Search | |
| Linear | Linear Search | |
| Linearithmic | Merge Sort | |
| Quadratic | Bubble Sort | |
| Cubic | Naive matrix multiplication | |
| Exponential | Subset generation | |
| Factorial | Permutation generation |
Relationship to Analysis Types
◇Worst-Case Analysis: maximum time over all inputs of size ◇Average-Case Analysis: expected time over all inputs of size ◇Best-Case Analysis: minimum time over all inputs of size
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 — doesn't mean "slow," it describes the growth rate. Forgetting that Big-O drops constants: is just . 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 , expressed using asymptotic notation (commonly Big-O). It is determined by counting primitive operations via frequency count analysis.
◇Links
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
- Previous Topic: ◇Substitution Method
- Next Topic: ◇Worst-Case Analysis
- Related Notes: ◇Space Complexity, ◇Running Time
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
What does time complexity measure?
How are primitive operations typically counted to determine time complexity?
Which notation is most commonly used to express time complexity by classifying its growth rate?
What is the time complexity of a simple array index access?
Which of the following time complexities is considered the most efficient (slowest growing)?
What does worst-case time complexity represent?
What does average-case time complexity represent?
Do we measure actual wall-clock time when determining theoretical time complexity?
What is a common pitfall regarding time complexity?
Why does simplify to ?