–L'Hôpital's rule (or sometimes spelled L'Hospital's rule) is a method used to find
limits of indeterminate forms in calculus.
–When you apply this rule (possibly multiple times), it can simplify an indeterminate
limit into a form that’s easier to evaluate by direct substitution.
–The rule is named after Guillaume de l'Hôpital, a French mathematician from the
17th century.
–However, the theorem was originally introduced to him by Johann Bernoulli, a Swiss
mathematician, in 1694.
L'Hôpital's rule
Guillaume de l'HôpitalJohann Bernoulli
–In mathematics, computer science, and engineering, it's often crucial to compare
how quickly different functions grow as their input � becomes large.
–Exponential functions are significant in these comparisons due to their rapid growth,
while logarithmic functions are notable for their very slow growth.
–Exponential functions, such as 2
??????
and �
??????
, grow much faster than polynomials or
rational functions as � increases.
–For example, 2
??????
grows much faster than �
2
as � becomes large. In fact, 2
??????
and �
??????
grow faster than any polynomial function, even those with very high powers like
�
1,000,000
.
–On the other hand, logarithmic functions like �=log
2� and �=ln� grow much
more slowly compared to any positive power of � as � increases.
Relative Rates of Growth
Fig. Comparing relative rates of growth.
Comparing Orders of Growth (Using Limits)
(Stirling's formula)
(L'Hôpital's rule)
Orders of growth from the lowest to highest.
O1 Best
Olog??????
O2log??????
O(??????)
O??????log??????
O(??????
2
)
O(??????
3
)
O(2
??????
)
O(??????!) Worst
Question 1
a) n(n+1) ≈ ??????
2
has the same order of growth as 2000??????
2
b) 100??????
2
≈ ??????
2
has a lower order of growth than 0.01??????
3
≈ ??????
3
c) log
2??????, ln?????? = log
????????????=lg ??????, log??????=log
10??????
– All logarithmic functions have the same order of growth
d) log
2
2
?????? = log
2?????? log
2?????? = (log
2??????)
2
log
2??????
2
= 2 log
2??????
(log
2??????)
2
has a higher order of growth than log
2??????
e) 2
??????−1
=
2
??????
2
=
1
2
2
??????
has the same order of growth as 2
??????
f) (??????−1)! Has a lower order of growth than ??????! = ?????? (??????−1)!
Useful summation formulas and rules
We use Summation to calculate
for loops run time.
Example: estimate the run time of the following.
for (i=0; i<n; i++)
print(i)
�=??????�??????????????????
??????��????????????
1 =
�����−??????�??????��+1
2
×(�??????���+????????????��)
�=0
??????−1
1=
??????−1−0+1
2
×(1+1)=??????∈ O(??????)
Example: estimate the run time of the following algorithm.
for (i=1; i<n; i++)
for (j=1; j<n; j++)
print(i)
�=1
??????−1
�=1
??????−1
1=
�=1
??????−1
??????−1−1+1
2
×1+1=
�=1
??????−1
(??????−1)=
??????−1−1+1
2
×??????−1+??????−1=??????−1
2
�=??????�??????????????????
??????��????????????
1 =
�����−??????�??????��+1
2
×(�??????���+????????????��)
∈ O(??????
2
)
Example: estimate the run time of the following.
for (i=n; i<=2n; i++)
for (j=1; j<=i; j++)
print(i)
�=??????�??????????????????
??????��????????????
1 =
�����−??????�??????��+1
2
×(�??????���+????????????��)
�=??????
2??????
�=1
�
1=
�=??????
2??????
??????−1+1
2
×1+1=
�=??????
2??????
??????=
2??????−??????+1
2
×??????+2??????=
3
2
??????
2
+??????
∈ O(??????
2
)
Example: Estimate Algorithm run time.
for (i=1; i<n; i++)
for (j=1; j<n; j++)
for (k=1; j<n; k++)
print(i)
Example:
i = 1
while i <= n
begin
print(i)
i = i + 2
end
We use trace to calculate while loops run time.
Let n = 5
i = 1, 3, 5
Let n = 8
i = 1, 3, 5, 7
Let n = 10
i = 1, 3, 5, 7, 9
3 times
4 times
5 times
�??????=
??????
2
or �??????=
??????+1
2
∈ O(??????)
Example:
i = n
while i >= 1
begin
for j = 1 to n
print(i, j)
i = i/2
end
Let n = 4
i = 4, 2, 1
Let n = 8
i = 8, 4, 2, 1
Let n = 16
i = 16, 8, 4, 2, 1
3 times
4 times
5 times
??????
�??????=log
2??????+1 × ??????
while loop for loop
=?????? log
2??????+??????∈ O(??????log
2??????)
log
2??????+1
Operation: doesn’t depend on input size. O(1)
for/while Loops:
++ increment: i = i + 1, i = i + 2, i = i + 5
– – decrement: i = i - 1, i = i – 3, i = i – 10
multiplication: i = i * 2, i = i * 5
division: i = i / 2, i = i / 9
Summary
O(??????)
O(log??????)
Conditions (if-else statements): maximum time of the conditions.
Example:
if (n > 3) {
print(n)
} else {
for(i = 1; i <= n; i*=2)
print(n)
}
Maximum(1,log??????) = O(log ??????)
O(1)
O(log??????)