

If f(n) = O(g(n)) and h(n) = O(k(n)) then f(n) + h(n) = O(g(n) + k(n)).
If f(n) = O(g(n)) and h(n) = O(k(n)) then f(n) * h(n) = O(g(n) * k(n)).
True Fact:
If f(n) = O(g(n)) then f(n) = O(a*g(n)) for any constant a > 0.
Incorrect Proof:
If f(n) = O(g(n)) then
lim n→∞[f(n)/g(n)] = 0.
Thus,
lim n→∞[f(n)/a g(n)] = 0.
Hence, f(n) = O(a*g(n)). Q.E.D.
- 1, if the matrix is a triangular matrix (either upper triangular, or lower triangular, but not both).
- 0, otherwise.
Consider "Euclid's" algorithm to calculate the gcd of two integers. For positive integers m, n: gcd(m,n) = largest positive integer that divides both m and n evenly (that is, without a remainder).
function Euclid(m, n) {
while (m > 0) {
temp = m
m = n mod m
n = temp
}
return n
}
Fib(0) = 0 Fib(1) = 1 Fib(2) = 1 ... Fib(n) = Fib(n-2) + Fib(n-1) for all n > 1.Here are the first few Fib(n) values: 0, 1, 1, 2, 3, 5 8, 13, 21, ... The following are two alternative algorithms for computing Fib(n):
function Fibrec(n) {
if (n < 2) return n
else return (Fibrec(n-1) + Fibrec(n-2))
}
function Fibiter(n) {
if (n<2) return n
else {
temp1 = 1
temp2 = 0
while (n>1) {
sum = temp1 + temp2
temp2 = temp1
temp1 = sum
n = n-1
}
}
return sum
}
function TimeFibrec(n) {
include a Python instruction here to start the clock
k = Fibrec(n)
include a Python instruction here to stopt the clock
include a Python instruction here to print n and the time
taken to calculate Fibrec(n)
}
function TimeFibiter(n) {
include a Python instruction here to start the clock
k = Fibiter(n)
include a Python instruction here to stopt the clock
include a Python instruction here to print n and the time
taken to calculate Fibiter(n)
}
Submit your full Python code as part of your HW submission.