AlgorithmsProgress: 0/1 completed
Subjects/Algorithms

Time Complexity & Big O

Medium
12 mins read
Prerequisites
  • 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 TermReal-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

Newdisk pe program
ReadyRAM Ready Queue
Dispatch
RunningCPU execution
TerminatedExit / Finished
I/O Wait
Waiting / BlockedI/O or Event
I/O Done
Note: Ready state queue holds processes waiting for CPU scheduler assignment.
Important Point
  • Big O represents worst-case boundary limit notation.
  • Theta (θ) represents average-case/tight-bound behavior.
  • Omega (Ω) represents best-case limit parameters.
Mnemonic / Memory Trick

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)

Mnemonic to remember order of time complexity growth from best to worst.
Avoid This Common Mistake
Students recursive algorithms me loop depth directly calculate linear format assumptions compile errors direct write out, recursion relation solving (like Master Theorem) is required.
GATE Exam Insights
Master Theorem conditions, divide & conquer relations and loop indices scaling factors are hot topics in GATE Algorithms segment.

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.