Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

Big-O, Little-o, Big-Omega, Little-Omega, and Theta notations #274

Open Qingquan-Li opened 1 week ago

Qingquan-Li commented 1 week ago

1. Big-O vs Little-o

Big-O Notation O(g(n))

Big-O Notation

Example:

If f(n) = 2n^2 + 3n + 5, we say f(n) = O(n^2) because n^2 dominates the growth of the function as n becomes large.

Little-o Notation o(g(n))

Little-o Notation

Example:

If f(n) = n, then f(n) = o(n^2) because n grows strictly slower than n^2.


2. Big-Omega vs Little-Omega

Big-Omega Notation Ω(g(n))

Big-Omega Notation

Example:

If f(n) = 5n^2 + 3n, then f(n) = Ω(n^2), because n^2 is the dominating term in the lower bound.

Little-Omega Notation ω(g(n))

Little-Omega Notation

Example:

If f(n) = n^2, then f(n) = ω(n) because n^2 grows strictly faster than n.


3. Theta (Θ) Notation

Theta (Θ) Notation Θ(g(n))

Theta notation

Example:

If f(n) = 3n^2 + 4n, then f(n) = Θ(n^2) because n^2 dominates both the upper and lower bounds.


Practical Application in Algorithm Analysis:

  1. Big-O Notation: Used to describe the worst-case running time or space complexity of an algorithm. For example, Merge Sort has a time complexity of O(n log n).

  2. Big-Omega Notation: Often used to describe the best-case scenario, or the minimum time an algorithm will take. For example, an algorithm may have a best-case complexity of Ω(n), indicating linear performance in the best scenario.

  3. Theta Notation: If an algorithm's running time is always the same (both best and worst case), we use Θ to describe its tight complexity. For example, an algorithm with time complexity Θ(n) always takes linear time, regardless of input.

  4. Little-o and Little-Omega: These are used less frequently in practice, but they provide more precise descriptions of growth rates, especially when comparing two algorithms. For example, if one algorithm grows strictly slower than another, we can say f(n) = o(g(n)).


Summary:

Big-O Big-Omega and Theta

all notations graph

Reference: https://www.slideshare.net/slideshow/asymptotic-notation-63320158/63320158