Académique Documents
Professionnel Documents
Culture Documents
Function f(n)
Input: n ≥ 0
Output: The value of n!
f := 1;
for i = 2 to n do
f := f ∗ i;
endfor
end.
Ceiling:
r + 1 ifs > 0
⌈x⌉ = ⌈r.s⌉ =
r ifs = 0
Floor:
r ifs < 1
⌊x⌋ = ⌊r.s⌋ =
r + 1 ifs = 1
Examples:
⌊3.4⌋ = 3, ⌈3.4⌉ = 4;
⌊−1.3⌋ = −2, ⌈−2.5⌉ = −2.
n ≥ log2 x.
Thus, the answer is ⌈log2 x⌉. From now on,
we denote by log n the expression log2 n. Some
relations about logs and exponentials:
c
= ab·c = (ac)b ;
a b a (ac) = ab+c;
b
g(n) ≤ cf (n)
holds. Then we say g(n) = O (f (n)).
g(n) ≥ cf (n)
holds. Then we say g(n) = Ω (f (n)).
n = o(n2).
n
X n−1
X
3
S3(n) = (i − 1 + 1) = (i + 1)3
i=1 i=0
n−1
X
= S3(n − 1) + 3S2(n − 1) + 3 i + n.
i=1
Fibonacci numbers:
F (n) = F (n − 1) + F (n − 2), F (1) = F (2) = 1.
We guess that F (n) = an? Then an = an−1 +
an−2 or a2 − a − 1 = 0. There exist two roots
of this equation,
√ √
a1 = (1 + 5)/2, a2 = (1 − 5)/2.
We can write the recurrence as
c1(a1)n + c2(a2)n.
Let
T (n) = aT (n/b) + cnk .
We assume b > 1, n = bm and T (1) = c.
Thus we get
First instance:
n−1
X
T (n) = c + T (i).
i=1
Another example:
n−1
2X
T (n) = n − 1 + T (i).
n i=1