Okay, let's prove this fundamental property of asymptotic notations.
We want to prove that for any two functions f(n) and g(n) (that are asymptotically non-negative, as is standard for these notations):
f(n) = Θ(g(n)) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n))
This is an "if and only if" statement, so we need to prove it in two directions:
Part 1: Prove that if f(n) = Θ(g(n)), then f(n) = O(g(n)) and f(n) = Ω(g(n)).
-
Assumption: f(n) = Θ(g(n))
-
By definition of Θ (Theta)-notation:
There exist positive constants c₁, c₂, and an integer n₀ such that for all n ≥ n₀:
0 ≤ c₁ * g(n) ≤ f(n) ≤ c₂ * g(n)
-
To show f(n) = O(g(n)):
We need to find a positive constant c_O and an integer n_O such that for all n ≥ n_O:
0 ≤ f(n) ≤ c_O * g(n)
From our Θ assumption, we have the inequality f(n) ≤ c₂ * g(n) for all n ≥ n₀.
We can choose c_O = c₂ and n_O = n₀. Since c₂ is a positive constant and n₀ is a valid threshold, this satisfies the definition of O-notation.
Thus, f(n) = O(g(n)).
-
To show f(n) = Ω(g(n)):
We need to find a positive constant c_Ω and an integer n_Ω such that for all n ≥ n_Ω:
0 ≤ c_Ω * g(n) ≤ f(n)
From our Θ assumption, we have the inequality c₁ * g(n) ≤ f(n) for all n ≥ n₀.
We can choose c_Ω = c₁ and n_Ω = n₀. Since c₁ is a positive constant and n₀ is a valid threshold, this satisfies the definition of Ω-notation.
Thus, f(n) = Ω(g(n)).
Since we have shown both f(n) = O(g(n)) and f(n) = Ω(g(n)), Part 1 is proven.
Part 2: Prove that if f(n) = O(g(n)) and f(n) = Ω(g(n)), then f(n) = Θ(g(n)).
-
Assumptions:
f(n) = O(g(n))
f(n) = Ω(g(n))
-
By definition of O-notation (from assumption 1):
There exist a positive constant c_O and an integer n_O such that for all n ≥ n_O:
0 ≤ f(n) ≤ c_O * g(n)
-
By definition of Ω-notation (from assumption 2):
There exist a positive constant c_Ω and an integer n_Ω such that for all n ≥ n_Ω:
0 ≤ c_Ω * g(n) ≤ f(n)
-
To show f(n) = Θ(g(n)):
We need to find positive constants c₁, c₂, and an integer n_Θ such that for all n ≥ n_Θ:
0 ≤ c₁ * g(n) ≤ f(n) ≤ c₂ * g(n)
For both of the conditions from our assumptions to hold simultaneously, n must be greater than or equal to both n_O and n_Ω.
Let n_Θ = max(n_O, n_Ω).
For all n ≥ n_Θ, we have:
f(n) ≤ c_O * g(n) (from the O-notation definition)
c_Ω * g(n) ≤ f(n) (from the Ω-notation definition)
Combining these two inequalities, for all n ≥ n_Θ:
c_Ω * g(n) ≤ f(n) ≤ c_O * g(n)
Now, let c₁ = c_Ω and c₂ = c_O.
Since c_O and c_Ω are positive constants, c₁ and c₂ are also positive constants.
And n_Θ is a valid integer threshold.
Therefore, we have found positive constants c₁, c₂, and an integer n_Θ such that for all n ≥ n_Θ:
0 ≤ c₁ * g(n) ≤ f(n) ≤ c₂ * g(n)
This is precisely the definition of f(n) = Θ(g(n)).
Thus, Part 2 is proven.
Conclusion:
Since we have proven both directions (Part 1 and Part 2), we can conclude that:
f(n) = Θ(g(n)) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)).