Professional Documents
Culture Documents
5 Counting
5 Counting
Counting
Objectives
Solution:
We must do ……….. times, each time we have …… ways to select
a bags.
Ex3: 12 teams. How many ways to select 3 teams for the first,
second and third teams.
Answer:
Basic Counting Principle
Ex3: 12 teams. How many ways to select 3 teams for the first,
second and third teams.
Answer:
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
10 ways
Ex4: Choose a 6 – character password: ****** (Note: * can be 0,
…,9, a,…,z, A,…Z)
How many possible passwords?
Answer:
Basic Counting Principle: Product rule
Ex7: How many one-to-one functions are there from a set with m
elements to one with n elements?
Answer:
Ex8: a. How many positive divisors does 120 have?
Answer:
b. In how many ways can a teacher seat 4 girls and 3 boys in a row
seats if a boy must be seated in the first and a girl in the last seat?
Answer:
Ex9: Given the set S = {1, 2, 3, 4, 5}
a.How many subsets of S can be constructed?
Definition 1:
Recurrence relation on the sequence { an }:
an is expressed in terms of one or more of previous items for all n with
n ≥ n0
o{an} is called a solution of recurrence relation.
oEx20: a0=3, a1= 5 an=an-1 – an-2 , n>1
oEx21: Determine whether {an} = 7, n ≥ 0 is a solution of the
recurrence relation an= 2an-1 – an-2, n ≥ 2?
Initial conditions: Terms that precede the first item where the
recurrence takes effect.
Modeling with Recurrence Relations
3 disks: H3 = 7 steps
The Tower of Hanoi Problem
f(n) = f(n/2) +2
Recurrence Relations for Finding Maximum of a
sequence
procedure max(i,j: integer ,ai,a2+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
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