Time Complexity & Big O
- Loops in programming
- Basic algebraic powers
Introduction
Algorithm analyze karte time, hume ye measure karna hota hai ki program input size (n) ke badhne par kitna slow ya fast chalega. Isi growth pattern ko quantify karne ke liye hum Time Complexity and Big O Notation use karte hain.
Real-Life Analogy
💡 Phone Book Search Analogy
Searching a contact in a large directory
| Concept Term | Real-life Analogy Mapping |
|---|---|
| Linear Search (O(n)) | Phone book ke har ek page ko sequentially check karna starting from page 1. |
| Binary Search (O(log n)) | Book ko direct middle se open karna aur side discard karke remaining half step bypass split karna. |
| Input Size (n) | Phone book me print kiye gaye total names. |
Detailed Concept Explanation
Time complexity standard notation is Big O (Upper Bound representation): - **O(1)**: Constant Time. Execution time scale linear changes se independent hai. - **O(log n)**: Logarithmic Time. Input elements range processing har instruction update cyclic split me half down adjust hoti hai. - **O(n)**: Linear Time. Input double hone par calculation duration directly double output leti hai. - **O(n²)**: Quadratic Time. Double nested loops execution.
Visual Diagram
- Big O represents worst-case boundary limit notation.
- Theta (θ) represents average-case/tight-bound behavior.
- Omega (Ω) represents best-case limit parameters.
C-L-L-N-Q-E (Chalo Log Laye Naye Quick Eatable)
Constant (1) < Logarithmic (log n) < Linear (n) < N Log N (n log n) < Quadratic (n²) < Exponential (2^n)
Practice Mini Quiz
Revision Summary (One-Page Notes)
- •Time complexity represents algorithmic growth rate.
- •Big O is the asymptotic upper bound.
- •Sorting and searching operations depend on time/space tradeoffs.