TheHingineer

  • Data Structures & Algorithms


  • DSA Part-1

  • DSA Part-2

  • DSA Part-3

  • DSA Part-4

  • DSA Part-5

  • Asymptotic Notations: Big-O, Omega, and Theta Notations

    Computer science me kisi bhi algorithm ko evaluate karne ke liye hume yeh dekhna hota hai ki jab input size (n) bohot bada ho jata hai (tends towards infinity), tab algorithm kitna time aur memory consume karta hai. Is behavior ko mathematically represent karne ke liye hum Asymptotic Notations ka use karte hain.

    Asymptotic analysis hardware specifications (CPU speed, RAM type) ya programming language compiler par depend nahi karta, balki algorithm ke intrinsic growth rate ko measure karta hai.

    Core Asymptotic Notations

    Engineering syllabus aur competitive exams me 3 primary asymptotic notations sabse important hote hain:

      Time f(n)
        ^
        |          c * g(n)  [Big-O: Upper Bound]
        |         /
        |       /  f(n) (Algorithm Running Time)
        |     /  /
        |   /  /
        | /  /       c * g(n)  [Omega: Lower Bound]
        |  /        /
        |/________/___________________> Input Size (n)
                n0 (Threshold)
    

    1. Big-O Notation (O) – Asymptotic Upper Bound

    Big-O notation kisi algorithm ke worst-case running time ko represent karta hai. Yeh batata hai ki algorithm kisi bhi halat me diye gaye upper bound se zyada time nahi lega. Yani yeh maximum time guarantee deta hai.

    Formal Mathematical Definition:
    Ek function f(n) = O(g(n)) hota hai agar aur sirf agar positive constants c aur n0 exist karein such that:

    0 <= f(n) <= c * g(n)    for all n >= n0

    Example: Agar f(n) = 3n + 5 hai, toh hum choose kar sakte hain c = 4 aur n0 = 5. For all n >= 5, 3n + 5 <= 4n satisfy hota hai. Therefore, f(n) = O(n).

    2. Big-Omega Notation (Ω) – Asymptotic Lower Bound

    Omega notation algorithm ke best-case running time ya minimum time requirement ko represent karta hai. Yeh batata hai ki algorithm kam se kam itna time toh lega hi; isse fast run nahi ho sakta.

    Formal Mathematical Definition:
    Ek function f(n) = Ω(g(n)) hota hai agar positive constants c aur n0 exist karein such that:

    0 <= c * g(n) <= f(n)    for all n >= n0

    Example: Agar f(n) = 2n^2 + 4n + 1, toh hum c = 2 aur n0 = 1 le sakte hain. Clearly 2n^2 <= 2n^2 + 4n + 1 for all n >= 1. Therefore, f(n) = Ω(n^2).

    3. Big-Theta Notation (Θ) – Asymptotic Tight Bound

    Theta notation tab use hota hai jab running time upper aur lower bounds dono taraf se same function se sandwich (bound) ho jaye. Yeh algorithm ka precise aur accurate growth rate batata hai.

    Formal Mathematical Definition:
    Ek function f(n) = Θ(g(n)) hota hai agar positive constants c1, c2 aur n0 exist karein such that:

    0 <= c1 * g(n) <= f(n) <= c2 * g(n)    for all n >= n0

    Little-o and Little-omega Notations

    Notation Meaning Condition
    Little-o (o) Strict Upper Bound (loose upper bound) f(n) < c * g(n) (Equality allowed nahi hoti)
    Little-omega (ω) Strict Lower Bound c * g(n) < f(n) (Strict inequality)

    Common Complexity Classes in Increasing Order

    Jab bhi algorithms ko compare kiya jata hai, growth rate ka hierarchy sequence yeh hota hai:

    O(1) < O(log n) < O(√n) < O(n) < O(n log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)

    Agli post me hum detail me samjhenge Time and Space Complexity Analysis aur loops, nested loops aur recursion ko calculate karne ke methods.

    Scroll to Top