Sub topic 3
Counting Lines, Triangles and Diagonals
This section assumes you know nCr, factorials, and the complement method from earlier chapters.
Counting Lines, Triangles and Diagonals
If no three of n points lie on one line, each pair of points makes one line. So the number of lines is C(n, 2). A triangle needs three points, so the number of triangles is C(n, 3). A diagonal joins two non-adjacent vertices of a polygon, so an n-gon has C(n, 2) - n diagonals.
import math
n = 6
print(math.comb(n, 2)) # 15 lines
print(math.comb(n, 3)) # 20 triangles
print(math.comb(n, 2) - n) # 9 diagonals of a hexagonDividing Objects into Groups
For unequal groups, divide by the factorial of each group size. Six distinct people split into groups of sizes 1, 2 and 3 give 6!/(1! 2! 3!) = 60 ways. For equal groups, also divide by the number of groups factorial, because the group labels are not distinct.
Stars and Bars
The number of non-negative integer solutions to x1 + x2 + x3 = 10 is C(10 + 3 - 1, 3 - 1) = C(12, 2) = 66. If every variable must be at least 1, the count is C(9, 2) = 36.
Dictionary Rank and Inclusion-Exclusion
The word CAT is third among the arrangements of A, C and T, because ACT and ATC come before it. For overlapping conditions, add the sets and subtract the overlap. Choosing 5 people from 6 men and 4 women, with at least 2 women, gives 252 - 6 - 60 = 186.
Derangements
A derangement is an arrangement where no object stays in its original place. D(n) = (n - 1)(D(n - 1) + D(n - 2)), with D(1) = 0 and D(2) = 1. So D(4) = 9.
Choosing a Method
Exercise
How many diagonals does an octagon have?
Show answer
C(8, 2) - 8 = 28 - 8 = 20 diagonals.