Summary
In this chapter, we primarily discussed how to count the cardinality, or size, of sets of different types. First, we looked at counting Cartesian products, where we take one element from each of a sequence of sets to create a new set. Counting the size of these comes down to the fundamental counting rule, which we used to count binary structures and the colors that can be displayed with HTML/CSS.
Second, we looked at permutations and combinations using factorials (for permutations) and binomial coefficients (for combinations), which we derived directly from the fundamental counting rule. For factorials, the key tool in Python is the factorial
function in the math
library and, for binomial coefficients, the binom
function from the SciPy library.
Lastly, we took a look at just a few applications of combinatorics in computer science, including memory allocation, the (poor) speed of brute-force algorithms in a few examples in the area of cryptology, and for a classical optimization...