Data Structures & Algorithms quick reference

3 entries — one card per concept, for looking something up rather than learning it. Each links back to the full explanation.

3

How to Think About a Problem

1

def solve(input: T) -> R | None: """Exact contract, including the None/edge case."""

A precise restatement fixes input/output types and every edge case (ties, no match, empty input) before coding starts.

def two_sum_indices(prices: list[int], target: int) -> tuple[int, int] | None: ...

Big-O and Complexity Analysis

2

O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!)

The complexity classes worth recognizing on sight, fastest to slowest.

n=20: 1, ~4, 20, ~86, 400, 1,048,576, 2,432,902,008,176,640,000