More Counting
Supplementary Notes
Prepared by Raymond Wong
Presented by Raymond Wong
1
X1 X2 X3 X4
1012
A number between 0 and 9
e.g.1 (Page 4)
The door code is 4 characters where each
character is a number between 0 and 9.
X1 X2 X3 X4
E.g.,
X1 X2 X3 X4
1012, 2561
How many door codes are there?
2
X1 X2 X3 X4
1012
X1
A number between 0 and 9
X2
X3
X4
0
1
0
1
0
1
0
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
6
6
6
6
7
7
7
7
8
8
8
8
9
9
9
9
10 choices
10 choices
10 choices
10 choices
Total no. of door codes = 10 x 10 x 10 x 10 = 104 = 10,000
3
D1 D2 D3 D4
abcD
{a, …, z, A…, Z}
e.g.2 (Page 5)
A password must be 4 characters long
where each character is in
{a, …, z, A…, Z}
D1 D2 D3 D4
D1 D2 D3 D4
D1 D2 D3 D4
E.g., abcD, DHrs, Mick
How many passwords are there?
4
D1 D2 D3 D4
abcD
D1
{a, …, z, A…, Z}
D2
a
b
a
b
…
D3
D4
a
b
a
b
…
…
…
z
z
z
z
A
A
A
A
B
B
B
B
…
…
…
…
Z
Z
Z
Z
52 choices
52 choices
52 choices
52 choices
Total no. of passwords = 52 x 52 x 52 x 52 = 524
5
D1 D2 D3 D4 D5 D6
abcdEF
{a, …, z, A…, Z}
e.g.3 (Page 5)
A password must be 6 characters long
where each character is in
{a, …, z, A…, Z}
D1 D2 D3 D4 D5 D6
D1 D2 D3 D4 D5 D6
D1 D2 D3 D4 D5 D6
E.g., abcdEF, DHrsAQ, Mickey
How many passwords are there?
6
D1 D2 D3 D4 D5 D6
abcdEF
D1
{a, …, z, A…, Z}
D2
a
b
a
b
…
D3
D4
D6
D5
a
b
a
b
a
b
a
b
…
…
…
…
…
z
z
z
z
z
z
A
A
A
A
A
A
B
B
B
B
B
B
…
…
…
…
…
…
Z
Z
Z
Z
Z
Z
52 choices
52 choices
52 choices
52 choices
52 choices
Total no. of passwords = 52 x 52 x 52 x 52 x 52 x 52 = 526
52 choices
7
L1 L2 D1 D2 D3 D4
AB1234
{0, …, 9}
e.g.4 (Page 6)
{A, …, Z}
Hong Kong car plates are of the form
L1L2D1D2D3D4
where
Li are letters in {A, …, Z}
Di are digits in {0, …, 9}
L1 L2 D1 D2 D3 D4
L1 L2 D1 D2 D3 D4
E.g., AB1234, EC1357
How many car plates are there?
8
L1 L2 D1 D2 D3 D4
AB1234
{0, …, 9}
{A, …, Z}
L1
L2
A
B
A
B
…
Z
26 choices
D1
D2
D3
D4
0
1
0
1
0
1
0
1
…
…
…
…
…
Z
9
9
9
9
26 choices
10 choices
10 choices
10 choices
10 choices
Total no. of car plates = 26 x 26 x 10 x 10 x 10 x 10 = 262 x 104 = 6,760,000
9
D1 D2 D3 D4
D1 D2 D3 D4 D5
D1 D2 D3 D4 D5 D6
abcD abcDE abcDEF
e.g.5 (Page 8)
D1 D2 D3 D4 D5 D6 D7 D8
…
abcDEFMK
{a, …, z, A…, Z}
A password is supposed to be between
4 and 8 characters long where each
character is in {a, …, z, A…, Z}
How many passwords are there?
10
D1 D2 D3 D4
D1 D2 D3 D4 D5
D1 D2 D3 D4 D5 D6
abcD abcDE abcDEF
D1 D2 D3 D4 D5 D6 D7 D8
…
abcDEFMK
{a, …, z, A…, Z}
P is a set of all possible passwords of length between 4 and 8
P4 is a set of password of length 4
No. of passwords = 524
P5 is a set of password of length 5
No. of passwords = 525
P6 is a set of password of length 6
No. of passwords = 526
P7 is a set of password of length 7
No. of passwords = 527
P8 is a set of password of length 8
No. of passwords = 528
P = P4 U P5 U P6 U P7 U P8
Total no. of passwords of length between 4 and 8 = 524 + 525 + 526 + 527+ 528
11
e.g.6 (Page 11)
E.g., Function from S to T
T
S
Range
Domain
S
T
S
T
12
e.g.7 (Page 11)
E.g., Not a function from S to T
S
T
S
T
13
e.g.8 (Page 15)
Write down all the functions from the
two-element set {1, 2} to the twoelement set {a, b}
S
T
1
a
2
b
14
S
T
1
a
2
b
S
T
1
a
2
b
S
T
1
a
2
b
S
T
1
a
2
b
15
S
T
2 choices 1
a
2 choices 2
b
Total no. of functions = 2 x 2 = 4
16
e.g.9 (Page 16)
How many functions are there from a
two-element set to a three-element set?
S
T
3 choices 1
a
3 choices 2
b
c
Total no. of functions = 3 x 3 = 9
Same as the number of 2-element lists from a 3-element list
17
e.g.10 (Page 17)
How many functions are there from a
three-element set to a two-element set?
S
T
2 choices 1
a
2 choices 2
b
2 choices 3
Total no. of functions = 2 x 2 x 2 = 8
Same as the number of 3-element lists from a 2-element list
18
e.g.11 (Page 18)
One-to-one Function (or injection)
S
T
S
T
19
e.g.12 (Page 18)
Not one-to-one Function (or not
injection)
S
S
T
T
20
e.g.13 (Page 18)
Onto function (or surjection)
S
S
T
T
21
e.g.14 (Page 18)
Not onto function (or not surjection)
S
T
S
T
22
e.g.15 (Page 20)
Bijection (or one-to-one correspondence)
S
T
a
1
2
3
b
c
4
d
S
1
2
S
1
3
2
3
4
4
Permutation
23
e.g.16 (Page 20)
Not bijection (or not one-to-one correspondence)
S
T
S
T
24
e.g.17 (Page 26)
List all the triplets (i, j, k) for the
following program when n = 4
(1) trianglecount = 0
(2) for i = 1 to n
(3)
for j = i+1 to n
(4)
for k = j+1 to n
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
25
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1 to n4
(4)
for k = j+1 to n4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
26
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
2
3
(4)
for k = j+1
to n4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
27
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
2
(4)
for k = j+1
to n4
4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
j=2
j=3
k=3
(1, 2, 3)
k=4
(1, 2, 4)
k=4
(1, 3, 4)
28
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
2
(4)
for k = j+1
to n4
5
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
j=2
j=3
k=3
(1, 2, 3)
k=4
(1, 2, 4)
k=4
(1, 3, 4)
j=4
29
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
3
(4)
for k = j+1
to n4
4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
i=2
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
j=3
k=4
(1, 3, 4)
j=3
k=4
(2, 3, 4)
30
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
3
(4)
for k = j+1
to n4
5
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
i=2
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
j=3
k=4
(1, 3, 4)
j=3
k=4
(2, 3, 4)
j=4
31
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
4
(4)
for k = j+1
to n4
5
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
j=3
k=4
(1, 3, 4)
i=2
j=3
k=4
(2, 3, 4)
i=3
j=4
32
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
5
(4)
for k = j+1 to n4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
i=2
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
j=3
k=4
(1, 3, 4)
j=3
k=4
(2, 3, 4)
i=4
33
(1) trianglecount = 0
(2) for i = 1 to n4
(3)
for j = i+1
to n4
5
(4)
for k = j+1 to n4
(5)
ifPrint
points
i, j, k are not collinear
(i, j, k)
(6)
trianglecount = trianglecount+1
n=4
i=1
i=2
j=2
k=3
(1, 2, 3)
k=4
(1, 2, 4)
j=3
k=4
(1, 3, 4)
j=3
k=4
(2, 3, 4)
(i, j, k) where
i<j<k
34
e.g.18 (Page 27)
Bijection between S and T
S: a set of triplets (i, j, k) where i < j < k
T: a set of 3-elements sets
T
S
(1, 2, 3)
(1, 2, 4)
{1, 2, 3}
{1, 2, 4}
(1, 3, 4)
{1, 3, 4}
(2, 3, 4)
{2, 3, 4}
35
© Copyright 2026 Paperzz