1.10.1 Comparison of Functions (part-1)
1.10.1 Comparison of Functions (part-1)
Overview
This lecture discusses methods to compare mathematical functions to determine their asymptotic relationships, particularly focusing on identifying which function is an upper bound and which is a lower bound. We explore both time and space complexity functions.
Methods for Comparing Functions
Direct Comparison by Sampling Values
- Concept: Directly sample values for each function to observe which one grows faster.
- Example:
- For
n = 2,n^2 = 4andn^3 = 8. Since4 < 8,n^3grows faster thann^2. - This method quickly provides an intuition about which function is the upper or lower bound.
- For
Logarithmic Comparison
- Concept: Apply logarithms to both functions to simplify the comparison.
- Example:
log(n^2) = 2*log(n)andlog(n^3) = 3*log(n).- Since
2*log(n) < 3*log(n), it confirmsn^2grows slower thann^3.
Key Logarithmic Properties
- Sum of Logs:
log(A*B) = log(A) + log(B) - Difference of Logs:
log(A/B) = log(A) - log(B) - Log of Exponent:
log(A^B) = B*log(A) - These properties are crucial for simplifying and solving logarithmic comparisons in complex functions.
Practical Function Comparisons
Example 1: f(n) = n^2*log(n) vs. g(n) = (n*log(n))^10
- Logarithmic Transformation:
log(f(n)) = log(n^2) + log(log(n)) = 2*log(n) + log(log(n))log(g(n)) = 10*log(n*log(n)) = 10*(log(n) + log(log(n)))
- Comparison:
- Simplifying,
log(g(n))grows significantly faster due to the factor of 10 applied to the entire logarithmic term.
- Simplifying,
Example 2: f(n) = n^3 and g(n) = n^root(n) * log(n)
- Direct Comparison without Logs:
- Both functions can be simplified to their core components, indicating they grow at similar rates asymptotically.
- Conclusion:
- The functions are asymptotically equivalent, though coefficients might influence immediate growth rates.
Summary
Through direct sampling and logarithmic transformation, we can effectively compare functions to determine their growth rates relative to each other. Understanding these comparisons is essential for algorithm analysis, optimizing performance based on time or space complexity. This lecture equips students with the analytical tools to assess and interpret the behavior of mathematical functions in computational settings.