Init guide environment...
Measures how the runtime of an algorithm increases as the size of the input (n) grows.
Measures how much extra memory an algorithm requires as the input size (n) grows.
The upper bound of complexity. It answers: "In the worst scenario, how bad can it get?"
Ω (Omega): Best-case scenario (lower bound).
Θ (Theta): Exact/average bound.
flowchart TD
%% Define styles
classDef excellent fill:#0d1117,stroke:#69f0ae,color:#fff,stroke-width:2px;
classDef good fill:#12161f,stroke:#1de9b6,color:#fff,stroke-width:2px;
classDef fair fill:#1a1f2b,stroke:#ffab00,color:#fff,stroke-width:2px;
classDef bad fill:#12161f,stroke:#ff6e40,color:#fff,stroke-width:2px;
classDef terrible fill:#0d1117,stroke:#ff5252,color:#fff,stroke-width:2px;
Start(["Input Size (n) Increases"])
O1["O(1)
Constant Time"]:::excellent
OlogN["O(log n)
Logarithmic Time"]:::good
ON["O(n)
Linear Time"]:::fair
ONlogN["O(n log n)
Linearithmic"]:::fair
ON2["O(n²)
Quadratic Time"]:::bad
O2N["O(2ⁿ)
Exponential"]:::terrible
OFact["O(n!)
Factorial"]:::terrible
Start -->|"Unchanged"| O1
Start -->|"Grows slowly"| OlogN
Start -->|"Grows proportionally"| ON
ON --> ONlogN
Start -->|"Grows rapidly"| ON2
Start -->|"Explodes"| O2N
O2N --> OFactAccessing the first element. Array size doesn't matter, it always takes 1 operation.
| Data Structure / Algorithm | Time: Best Case | Time: Worst Case | Space (Worst Case) |
|---|---|---|---|
| Array Access | O(1) | O(1) | O(n) |
| Search (Unsorted Array) | O(1) | O(n) | O(1) |
| Binary Search (Sorted Array) | O(1) | O(log n) | O(1) |
| Merge Sort | O(n log n) | O(n log n) | O(n) |
| Bubble Sort | O(n) | O(n²) | O(1) |