Professional Documents
Culture Documents
05 Counting
05 Counting
Counting
Objectives
Ex: Distribute 3 v A
distinct balls to 2 bags v
v B
We must do 3 times,
v A
each time we have 2
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
12 teams. How many ways to select 3 teams for the first, second and third teams
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
an: number of bit string of length n that do not have two consecutive 0s.
One bit string can terminate with bit 1 or 0
Format of a bit string that do not have two consecutive 0s:
f(n) = f(n/2) +2
Recurrence Relations for Finding Maximum of a
sequence
procedure max(i,j: integer ,ai,ai+1,…,aj: integers)
if i=j then
begin f(n) = 2f(n/2) +1
max:= ai
end
else
begin
m= (i+j)/2
max1= max (i,m,ai,ai+1,…,am)
max2= max (m+1,j,am+1,am+2,…,aj)
if max1>max2 then max:= max1
else max:=max2
Theorem 1
Let f be an increasing function that satisfies the
recurrence relation f(n)= af(n/b) + c
whenever n is divisible by b, where a ≥ 1 , b is an integer
and greater than 1, and c is a positive real number. Then
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.
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