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 and the answer to the second is . 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 computer science textbooks and math textbooks. If you want to buy only one textbook, then you have 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.
Let's use set theory. If is the set of ways to do one task and is the set of ways to do another task, and if and are disjoint, then the ways to do either the first or second task are (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 represents the cardinality of the set .
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 such distinct paths. Since there are choices for the first book and for the second, there are ways to buy both books. We used the rule of product to solve this problem.
In terms of set theory, if is the set of ways to do one task and is the set of ways to do another task, then making a choice from and a choice from can be represented as the ordered pair . We denote all possible pairs with and call it the Cartesian product. The rule of product says that the cardinality of the Cartesian product of sets and is equal to the product of the cardinalities of the individual sets.
Difference rule
Let be a subset of set . If the number of elements in both and are known, then the number of elements that are in but not in can be computed as
The difference rule follows immediately from the rule of sum. If is a subset of , then and have no elements in common. So, . By the rule of sum,
Here is an example to illustrate the difference rule. How many three-digit integers (from to 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 repeating digits and repeating digits. For the integers with 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 be the set of all three-digit integers and be the set of all three-digit integers with no repeating digits. Then 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 to . The first digit of every three-digit integer must be from the set (in other words, it cannot be ). The second and third digits are from the set . By the rule of product, there are such numbers. So, .
Now, you need to figure out how many three-digit integers have no repeating digits. For the first digit, there are possibilities. For the second digit there are possibilities since it can be but cannot be the same as the first digit. Similarly, for the third digit there are possibilities as it has to be different from the first two digits. By the rule of product, there are such numbers. Therefore, .
Using the difference rule, you can calculate how many three-digit integers have repeating digits. Thus, there are 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 hot beverages and cold beverages. For the food item, you can choose from types of sandwiches, types of pizzas, and types of salads. How many possible meals can you choose from?
Here's the solution:
First, pick one beverage from hot beverages and cold beverages. Using the rule of sum, you have options for your drink.
Next, pick one food item from sandwiches, pizzas, and salads. Again, using the rule of sum, you have options for your food item.
Since you have 8 drink options and 12 food item options, you have 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 choices for one task and 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 (). 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 ().