Ω, O, Θ- Notations
Algorithm Efficiency
By: Khuchu, Isaac,
Thomas, Tim
2 ways to search the Yellow Pages
Method 1
-
Start at the first page
Go through the page line by line
Method 2
-
Start at the halfway point
Check if the name is before or after
the halfway point alphabetically
Choose one half, rip out the other
Start at the halfway point of the
remaining half
Repeat
The Problem
Which method was faster?
Would the answer be different with a different person?
How would the number of pages change the time it takes?
These questions don’t really have a clear time-based answer. How can we
compare methods without relying on how fast someone reads?
The Solution
Let’s compare how many times we have to check to get through all lines
Method 1
-
Every line, every page.
Method 2
-
As many bisections as it takes
10 pages, 20 lines - 200 checks
10 pages, 20 lines ~ 7 checks
1,000,000 pages - 20,000,000 checks
1,000,000 pages ~ 25 checks!
Clearly, some algorithms grow differently compared to others
Modeling Growth: Linear vs Logarithmic
THREE
Big-O (O)
Big-Omega (Ω)
Big-Theta (Θ)
The Upper Bound. Represents
The Lower Bound. Represents
The Tight Bound. When an
the "At Most" performance.
the "At Least" performance.
algorithm is both O and Ω of the
Crucial for worst-case analysis to
Used to find the fundamental
same order, it is defined by Θ.
guarantee reliability.
limits of a problem.
Ω(n)- The Floor
Example:
O(n) - The ceiling
Θ(n) - The middle ground
EXECUTION BENCHMARKS
Estimated execution time assuming 1 operation per nanosecond:
Order
n = 1,000
n = 100,000
n = 10,000,000
log n
10⁻⁸ sec
1.7 × 10⁻⁸ sec
2.3 × 10⁻⁸ sec
n log n
10⁻⁵ sec
0.0017 sec
0.23 sec
n²
0.001 sec
10 sec
27.8 min
n³
1 sec
11.6 days
31,688 years
Returning to the Yellow Pages
Method 1 (Sequential Search)
-
What’s O(n)?
What’s Ω(n)?
What’s Θ(n)?
Method 2 (Binary Search)
-
What’s O(n)?
What’s Ω(n)?
What’s Θ(n)?
CASE STUDY: Sequential Search
Best Case: Ω(1)
Worst Case: O(n)
Occurs when the target item is the very first item in
Occurs when the target item is last or missing.
the array.
Number of comparisons: 1. Independent of array size .
Number of comparisons: . Direct linear relationship to
input size.
CASE STUDY: Binary Search
Best Case: Ω(1)
Worst Case: O(log n)
Occurs when the target item is the very first item in
Occurs when the target item is last or missing.
the array.
Number of comparisons: 1. Independent of array size .
Number of comparisons: . Direct logarithmic
relationship to input size.