05 Counting
05 Counting
05 Counting
Counting
Objectives
⚫ Ex: Distribute 3 v A
distinct balls to 2 bags v
v B
⚫ We must do 3 times,
A
each time we have 2 v
v A
ways to select a bags. A v
⚫ 2.2.2 = 23 ways v B
B
v A
v
B v B
Basic Counting Principle
I
II III
Select 1/ 12 After select 1 team for the first After select 1 team for the
→ 12 ways position, one of 11 teams can second position, one of 10
be select into the second team remaining teams can be select
➔ 11 ways into the third team
➔ 10ways
f(n) = f(n/2) +2
Recurrence Relations for Finding Maximum of a
sequence
f (n) = C1nlogb a + C2
Using Theorem 1
Theorem 2: Master Theorem
Theorem 2: Master Theorem
An Demonstration: Closest-Pair Problem
Total number of
points in the strip
does not exceed n
and there are at
most 8 points,
including p, can lie
in or on the 2dxd
rectangle.
➔A point will be computed with 7 others.
➔At most 7n distances need to be compare with d to find the minimum
distance between points.
➔ The increasing function f(n) satisfies the recurrence relation :
f(n) = 2f(n/2) + 7n
➔ By the Master Theorem, it follows that f(n) is O(nlogn)
Summary
f (n) = C1nlogb a + C2
Where C1=f(1) + c/(a-1) and C2= -c/(a-1)
Proof: page 477
Summary – Theorem 2- Master Theorem
O(n d ) if a b d
f (n) is O(n d log n) if a = b d
O(n logb a ) if a b d
⚫ THANKS