8 minutes read

Imagine that you go to a bookshop and see two textbooks on computer science, and three on mathematics. How many choices do you have if you want to buy just one textbook? In how many ways can you buy exactly one computer science textbook and one math textbook?

This example problem falls under combinatorics, which is a branch of mathematics that deals with counting. Two intuitive rules that are useful for solving such combinatorial problems are the rule of sum and rule of product. These rules are also "building blocks" for more complex concepts.

In case you're curious, the answer to the first question is 55 and the answer to the second is 66. Keep reading to learn how to solve these kinds of problems.

Rule of sum

Let's revisit the problem from the introduction. You have the choice of 22 computer science textbooks and 33 math textbooks. If you want to buy only one textbook, then you have 2+3=52+3=5 choices. It is important to note that a textbook can fall into only one category: either computer science or math. Use the rule of sum to solve this problem.

The rule of sum says that if there are nn choices for one task and mm choices for another task, then there are n+mn+m ways to do one of these tasks if these two tasks cannot be done at the same time.

Let's use set theory. If AA is the set of ways to do one task and BB is the set of ways to do another task, and if AA and BB are disjoint, then the ways to do either the first or second task are ABA \cup B (the union of set A and B). The rule of sum states that the number of elements in the union of these two sets is equal to the sum of the number of elements in the individual sets. Note that A|A| represents the cardinality of the set AA.AB=A+B|A \cup B| = |A| + |B|

Rule of sum

Rule of product

Let's go back to our bookshop problem. How do you calculate the number of ways you can buy one computer science textbook and one math textbook? Let's draw a tree to depict our scenario. Also, let's assume that you choose the computer science textbook first and then the math one. The possible ways for the books to be bought are represented by the distinct paths from the root to the leaf of the tree. In this tree there are 66 such distinct paths. Since there are 22 choices for the first book and 33 for the second, there are 23=62 \cdot 3=6 ways to buy both books. We used the rule of product to solve this problem.

Rule of product

The rule of product says that if there are nn choices for one task and mm choices for another task that is performed after the first one, then there are nmn \cdot m ways to do both of these tasks.

In terms of set theory, if AA is the set of ways to do one task and BB is the set of ways to do another task, then making a choice aa from AA and a choice bb from BB can be represented as the ordered pair (a,b)(a,b). We denote all possible pairs with A×BA \times B and call it the Cartesian product. The rule of product says that the cardinality of the Cartesian product of sets AA and BB is equal to the product of the cardinalities of the individual sets.

A×B=AB|A \times B| = |A| \cdot |B|

Difference rule

Let CC be a subset of set AA. If the number of elements in both AA and CC are known, then the number of elements that are in AA but not in CC can be computed as AC=AC|A-C|=|A|-|C|

Difference rule

The difference rule follows immediately from the rule of sum. If CC is a subset of AA, then ACA-C and CC have no elements in common. So, C(AC)=AC \cup (A-C) = A. By the rule of sum,

C+AC=A|C| + |A-C|=|A|

Here is an example to illustrate the difference rule. How many three-digit integers (from 100100 to 999999 inclusive) are there that have repeating digits?
On first thought, you might try to count all the integers that have repeating digits. These would include integers with 33 repeating digits and 22 repeating digits. For the integers with 22 repeating digits, the non-repeating digit could occur as the first, second, or third digit. Wow, this is getting complicated!

Instead, let's figure out how many three-digit integers don't have repeating digits. Then subtract that amount from the total number of three-digit integers.

Let SS be the set of all three-digit integers and NN be the set of all three-digit integers with no repeating digits. Then SNS-N is the set of all three-digit integers that have repeating digits.

Firstly, you need to figure out how many three-digit integers there are from 100100 to 999999. The first digit of every three-digit integer must be from the set {1,2,,9}\{1, 2, …, 9\} (in other words, it cannot be 00). The second and third digits are from the set {0,1,2,,9}\{0,1, 2, …, 9\}. By the rule of product, there are 91010=9009 \cdot 10 \cdot 10 = 900 such numbers. So, S=900|S| = 900.

Now, you need to figure out how many three-digit integers have no repeating digits. For the first digit, there are 99 possibilities. For the second digit there are 99 possibilities since it can be 00 but cannot be the same as the first digit. Similarly, for the third digit there are 88 possibilities as it has to be different from the first two digits. By the rule of product, there are 998=6489 \cdot 9 \cdot 8 = 648 such numbers. Therefore, N=648|N| = 648.

Using the difference rule, you can calculate how many three-digit integers have repeating digits. SN=SN=900648=252|S-N| = |S| - |N| = 900-648 = 252Thus, there are 252252 three-digit integers that have repeating digits.

Example using both rule of sum and rule of product

At a restaurant, you can buy a meal which consists of one drink and one food item. For the drink, you can choose from 33 hot beverages and 55 cold beverages. For the food item, you can choose from 44 types of sandwiches, 66 types of pizzas, and 22 types of salads. How many possible meals can you choose from?

Here's the solution:
First, pick one beverage from 33 hot beverages and 55 cold beverages. Using the rule of sum, you have 3+5=83+5 = 8 options for your drink.
Next, pick one food item from 44 sandwiches, 66 pizzas, and 22 salads. Again, using the rule of sum, you have 4+6+2=124+6+2 = 12 options for your food item.
Since you have 8 drink options and 12 food item options, you have 812=968 \cdot 12 = 96 options for your meal. We use the rule of product here, because the task of choosing a drink and the task of choosing a food item are both performed.

Conclusion

Suppose that there are nn choices for one task and mm choices for another independent task.

Use the rule of sum in situations when you must perform one task from a list of independent tasks. You can calculate the number of ways you can select a task through addition (n+mn+m). The difference rule is a special case of the rule of sum, and it allows reaching the desired solution by counting "bad" options (that is, the desired set's complement) and subtracting them from the total number of options.

Apply the rule of product when you must perform multiple tasks one after the other. You can calculate the number of ways you can perform these multiple tasks through multiplication (nmn \cdot m).

23 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo