Introduction to Sets
Transcript
Even when the contents stay the same, rearranging them can make everything feel different. Think of your playlists, for example. The same songs, just shuffled, can change the vibe. So, why don't we stop and discuss distinct objects to see what we can learn from them? Before we dive into calculating combinations and building structures, we should first examine how we organize items in mathematics. That brings us to one of the core ideas: sets. Sets: To understand
how we organize things in math, we begin with sets. We often group items together, like putting them into a bag. The items inside are called elements, and the bag itself is the set. Typically, we don't care about the order in which we place items in the bag. We can shake our imaginary bags however we like — the same idea applies to sets. Imagine searching for a lost bag that contains a photo, a business card, and a ten-dollar bill. Then someone finds a bag with those same items,
just in a different order. You’d still say that’s your bag: same items, different order. And unlike a real bag, a set isn’t limited by space — it can even contain an infinite number of elements. Sets don’t allow duplicates — they care only about whether something is in the set, not how many times it appears. The definition of “distinct” can be a bit ambiguous. Are two blue shirts distinct elements? What if one has a different size? Since what counts as “distinct” can be subjective, we need to define our sets clearly. We should be able to tell exactly which elements belong and which do not. A set of 'tall people' is vague — but if we define 'tall' as above 6 ft, it becomes well-defined. We’ve now laid the groundwork for sets. They have the following characteristics: Orderless – Order doesn’t matter. Unbounded – Can have any number of elements. Distinct – No duplicates allowed.
Well-defined – Clear what belongs and what doesn’t. We could go deeper into this topic, but I’ll draw the line here for now — maybe we’ll revisit it in a later video. Now that we have a solid understanding of sets, it's time to explore what we can do with them. That brings us to arrangements, selections, and permutations — which leads us into the field of… Combinatorics: I'm dividing this chapter’s ideas into different levels or categories. Some you’ll use all the time, others only in specific situations — but they’re all useful when the right problem arises. Some even show up in daily life or at math olympiads. Let's begin with the first one. Rules for Sum and Product:
Consider purchasing a school lunch. There are fifteen varieties of drinks and ten varieties of toast. Every day you want a different lunch, with just one piece of toast and one drink. Many of you have probably already multiplied these numbers — 10 times 15 — to get 150. Consider the drinks as a set D with fifteen elements, and the toasts as a set T with ten. Every lunch combines one item from T and one from D.
Imagine a grid with rows for toast options and columns for drinks. Every cell represents a distinct lunch, consisting of one piece of toast and one drink. This grid creates a rectangle in geometry. Its area (10 × 15) indicates that there are 150 possible lunches. What if the question changed? What if we want to count lunches with either a toast or a beverage, instead of both? How would that change our answer? In this case, we line up all options in a
row — the 10 toasts and 15 beverages. The total number of options is the sum: 10 + 15 = 25. We call these the product and sum rules: if the problem uses 'and,' we multiply; if it uses 'or,' we add. Permutations Now we can start asking questions about order — the sequence in which things happen or are arranged. And to answer them, we’ll use our old friends: the product and sum rules. Let's imagine all the different ways we can draw 10 cards - ace to 10 of hearts.
We can consider two approaches to this. We can select a random card from the deck, remove it, and repeat this process. This model is known as the selection model, where we select cards from a deck. Alternatively, we can choose a card and allocate it to a specific location, then leave the card there. This model would be the allocation model. Both approaches give us the same result — as we’ll see. For our first draw, we have to pick from one of ten cards,
AND then we only have nine cards to choose from. Only nine since we drew this card [insert name] and put it to the side. Repeating the process, we lose cards until we run out of cards. So, first 10 options, then 9, then 8, and so on, down to 1. Multiplying these together gives 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1, which equals 3,628,800 ways. That was selection; now let's discuss allocation. We do it by selecting which card to
place next into a predetermined location. For the first spot, we can choose any of the 10 cards. And then we choose a second card from the nine remaining cards and place it into the second spot. Then again, from the eight cards left, and so on, until we fill all the spots. Since I don't want to list out all the numbers from 10 down to 1, we have a shorthand: 10! (read as "ten factorial"). No, I’m not shouting in excitement about the number 10! When we say “10 factorial,” written as 10!, it means multiplying every whole number from 10 down to 1. 10! = 10 × 9 × 8 × … × 1. This calculation gives us the total number of ways we can allocate the cards to the spots. We call this problem a permutation. These cards were a permutation of 10 cards. However, its limitation is that you have to place down every card. What if we draw only four cards out of the 10? We would be dealing with … Variations
We should always know how many objects we have and how many selections or allocations we have. So let's say I'll only draw four from ten cards. As we see, we can select or allocate any 10 of these cards, then 9, then 8, AND then 7. After four draws, we’re out of picks — so we stop there. That gives us 10 × 9 × 8 × 7. Let's call this number our variation. Variation differs depending on the number of objects and the number of draws. It would be efficient if we were to write this in
factorial form, wouldn't it? Can you think of any other way to describe this product? Let me help you out — wouldn’t it be nice if that could be written as 10!? Imagine the number of ways to draw 4 cards from 10 in order, followed by arranging the remaining 6 cards. The total number of ways to arrange all 10 cards is 10! We can split this into two parts: the ways to arrange the first 4 cards (our variation), and the ways to arrange the remaining 6 cards (which is 6!). Using the product rule, variation × 6! = 10! So, to find the variation, we divide both sides by 6!, giving: variation = 10! / 6!.
If we expand our factorials into products, we can see that canceling out the numbers yields our original product again. We can also rewrite the 6! as (10-4)! Hopefully, you can see that the six factorial was just the factorial of cards minus the picks; therefore, if we rewrite our four picks as p and the total number of cards as n, we get the general formula for variation: If we pick all the cards, we get 0! in the
denominator. You might think 0! equals zero and be worried about dividing by zero. But by definition, 0! equals 1 — because there’s exactly one way to arrange nothing: by doing nothing. By adjusting our formula, we obtain our previous formula for permutations. Permutations are just variations, where you select or allocate all the items. Extensions of Permutations - Ring permutation In our previous examples, we placed objects in a straight line.
But what happens if we place them in a circle? How will the number of unique rings change? I'll let you think about it. Let's say we have five gemstones: Blue, Green, Red, Pink, and White. If we arrange the gemstones in a ring, rotating the ring produces 5 different views, but we consider all those rotations as the same unique arrangement. That means the number of unique circular arrangements is fewer than the linear permutations. We divide the number of
line permutations by 5 — one for each possible rotation — to get the number of unique rings. Imagine first arranging the gemstones in a straight line. We already know there are "five factorial" ways to do this — that means multiplying 5 × 4 × 3 × 2 × 1. So, the number of unique rings is 5!/5. After cancelling out the 5, we get "four factorial," which is 4 × 3 × 2 × 1. In general, if we have n items, imagine arranging n gemstones in a straight
line. There are n!n!n! ways to do this. When we tie the line into a ring, we can “hold onto” any one of the n gemstones as a reference point. Rotating the ring around that gem doesn’t create a new arrangement, so we divide by n, giving (n−1)! unique rings. Now, let's add one more idea. What if we also consider mirror images — flipping the ring over — as being the same ring? In that case, each unique view has a matching mirror view, so we should divide by 2 afterwards.
Therefore, the general formula for unique rings can be either (n-1)! or (n-1)!/2. Which one we use depends on the inclusion of mirror images or not. You might even try thinking about ring variations instead of full permutations. I’ll let you explore that. Now, let’s focus on another upgrade of our formulas before we dive into something more complicated: Generalized permutations Until now, our formulas have assumed that every item is unique. This assumption can be problematic when we intentionally add two of the same item.
To resolve this, we need to think everything is distinct at first. After the grand reveal, we look at the identical items. Notice that if we mix them up, we still have the same permutation. It’s like shuffling three identical cards—they swap places, but nothing really changes. If we calculate the number of different ways we could permute the duplicates, then we know what to divide by. So, you divide the total number of permutations by the number of permutations of the duplicates,
because those swaps don’t actually create new arrangements. If we have multiple groups of duplicates, we go group by group, dividing each time, until we find the proper amount of permutations. For example, the word "Consensus" has nine letters, amongst which are 3 Ss, 2 Ns, 1 C, 1 O, 1 E, and 1 U. If we had unique letters, we would have 9! permutations of these letters. If we look at S specifically, we can permute those in 3! ways. The two N’s in 2! ways, and the single C in 1! way. Remember that dividing by 1 does nothing; therefore, we can ignore the single-letter groups. We get to our final answer of 9!/3!*2!
or after calculations 30,240 new words, by jumbling the word “Consensus”. Combinations We already discussed permutations and variations, but perhaps you've noticed that I avoided saying the word combination. In combinatorics, the word combination has a strict meaning, which I'll explain after recapping the differences between permutations, variations, and the newly added combinations. Permutations are the number of ways you can select or allocate ALL cards when you care about order.
Variations are the number of ways you can select or allocate some cards when you care about order. In the new combinations, you have the freedom of choosing the number of cards, like in variations, but you don't care about the order. Let's see why order sometimes doesn't matter. Imagine you and your friends are picking three toppings for a pizza out of 10 choices. No, you can't add the same topping twice. Whether you choose cheese first, mushrooms second,
and olives third — or olives first, cheese second, mushrooms third — you'll still end up with the same pizza. What matters is which toppings you chose, not the order you chose them in. Again, that's selection. In allocation, we imagine it as placing items in 3 indistinguishable places. Here’s a comparison of allocation between permutations and combinations. How do we obtain the formula? We can start with a variation of n items and p picks.
We can imagine that the p selected items can be arranged in p! different ways. However, since the order doesn’t matter, we divide by p! to avoid counting the same choice multiple times. Thus, each combination has p! ways to mix them. So, the combinations * p! = variations of p out of n, or C = V/p!. Let’s make this formula more concrete. We can express variations using factorials. V is n!/(n-p)! Dividing by p! gives n! / [(n-p)! p!], which is the formula for combinations of
p picks from n items. Sometimes we can write it in these brackets, which translate to n choose p. There are a few tricks that reveal themselves. Essentially, there are several ways to rewrite combinations. We call these combinatorial identities. I'm going to highlight two, but there are many more. For example, for n items, choosing p is the same as not choosing p. Sounds contradictory, but it isn't;
trust me. Not picking p means we choose n-p to be part of our combinations. If we put this into the factorial form, we can see that we can manipulate the formula to derive the formula for n choose p. —-- DONE ^^^^^ Here’s a second identity that shows another interesting property of combinations. The combination of n choose p is the sum of n-1 choose p and n-1 choose p-1.
How would we go about this? Let's put our n items into the set X and choose all except for one to be part of set Y. Thus, X has n items, while Y has n-1 items. The item that is in X and not in Y will be our "target". Either the p choices will include the target, OR not. Therefore, we can divide our problem into two paths that we can sum together. Path 1: target not chosen We can then conclude that all the p choices were in the set Y, so we need to find how many ways p choices fit
into n-1 spots without considering order. Reminds you of something? We can write that as n-1 choose p. Now we should quickly move onto the alternative, which is … Path 2: target chosen That means one of the choices will be the target, and the rest will be in the set Y. Since the choice of target is guaranteed, we only care about the combinations of the p-1 choices in set Y, which can be expressed as n-1 choose p-1. In the end, we sum the formulas of these two
possibilities to obtain the final formula. This specific identity is known as the Pascal identity, and we can create an interesting pattern from it, which can help us in other problems. Pascal Triangle Let's examine n choose p. We already know what we just interpreted it as, but let's consider them as coordinates for now, where n is the row and p is the column. Our n and p can be any whole number that isn't negative,
since you can't have -1 items or choose -2 items. In such cases, we will consider them to have zero combinations. [Panning motion showing zeros in -1th row and -1 column.] Starting with the upper left corner at 0,0, we can calculate that there is only one combination. I'd also like to note that it doesn't make sense to choose more items than we have. So when we have p greater than n, then we also define it as 0. Therefore, the rest of this row will be 0's.
Surprisingly, we can obtain the remaining numbers by using Pascal's identity. To reach a square, add the value above it and the one to the top-left. Since n-1 means we have to move to a row with a smaller value and p-1 to column with a smaller value. We can then slide this shape to the right to create a new row. We can continue building rows indefinitely, but this is enough for now. We can move this triangle into its often-depicted form. There it is! The Pascal triangle. You are
right to question the usefulness of this, apart from being able to quickly find the number of combinations just from reading this triangle. We can discover more properties of combinations. For example, notice these diagonals; each has an interesting sequence that I could discuss further in the future. Though more importantly, look at each row. If we were to sum up each row, we get the sequence 1, 2, 4, 8, 16, 32, 64, and so on. Computer scientists might recognize that these are powers of two, or respectively, 2^0, 2^1, 2^2, 2^3,
and so on. There's a perfect explanation for that, which brings us to the use of the Pascal triangle. The Binomial Theorem Some of you might recognize that (a+b)^2 is a^2 + 2ab + b^2, but how would you find the general formula, for example, for (a+b)^5? Would you multiply all the terms? There is a quicker way. Imagine we expand our expression. We get five brackets of a+b. In each bracket, we are free to choose to multiply either variable
A or B first. So we have two choices. Then we should do the same thing for the second bracket, the third, and the fourth, and so on. We have two choices for each, and we use the AND operator, so we should multiply the number of options. So we get 2*2*2*2*2 or 2^5. So, if we expand (a + b)^n,
we should get 2^n terms. Alternatively, if we add up like terms, the coefficients should add up to 2^n. That gives us a connection to the powers of two in the Pascal triangle, but you are perfectly fine not to accept that explanation yet. To get a complete understanding of the connection between the term expansion and the Pascal triangle, I should ask, for example, "How many of the terms a^2b^7 are there in the expansion of (a+b)^9?" Firstly, I'd be interested
to check whether it makes sense for the term to be there. The 9 in (a+b)^9 means how many choices we should make, and a^2 means we chose "a" twice. You can't select anything if the exponents or "how many times you chose a variable" don't add up to the total number of choices you were supposed to make. It shows that you either didn't choose completely or made a choice that wasn't there.
The abundance of the word "choices" here may have sounded a few alarms. Can we use combinations to describe this expansion? Yes, we can! How many different ways can you choose "a" twice out of 9 times? Hm… 9 brackets choosing 2? Sounds like we should look at 9 choose 2! That would mean we have 36 of the terms a^2b^7. Could we have chosen to look at the number of combinations of choosing "b" 7 times out of nine instead? Yes, we could, and it would lead to the same calculation.
Remember how I said choosing p times is the same as not choosing p times? We concluded that picking p is the same as picking n-p, which would correspond to our "a" and "b" cases. — DONE — Alright, this was a mouthful. Can we generalize it? We can! For (a + b)^n, it is the same as adding up the terms. We can express them as a^p*b^n-p
where p is the number of times "a" was chosen. We replace numbers with p using the summation symbol, indicating the range of choices. At the bottom, we indicate what p starts as, and at the top, we indicate the limit. We know that "a" can be chosen up to n times, and more would be nonsensical. We also know that you can’t select less than zero. We should also add a coefficient to each term. Like we said. It's a combination of n choose p. We refer to these as the "binomial coefficients.", and there it is! This is a condensed formula for (a+b)^n.
Although the big picture emerges when we expand it fully. No summation, no brackets. For example (a+b)^n is a^2 + 2ab + b^2. If we add a coefficient of 1 before a^2 and b^2, we get this. If we only look at the coefficients, does this remind you of something else? If you were to say the row of a Pascal triangle? You'd be right. If you expand and order terms of the expanded binomial, you have the coefficients that appear on the triangle. Impressive. Let's also notice how symmetrical it is. That is again because of the identity n choose p being the same as not choosing p. However, some of you might be interested
in trying solutions, such as (x+y+z)^5. How would we solve that? Unfortunately, Pascal's triangle lacks in this sense. We'd have to use a different tool, which we will focus on now. Generalized combinations. After a long time, we could categorize items into multiple groups, not just "chosen" and "not chosen." Each of the groups has a limited size that has to be filled. For example, let's imagine you're supposed
to split ten types of candy among the three of your friends. Let's say they are people A, B, and C. Each has to take three candies - that's fair. We can put the last one to the side. The question is, how many different ways can you guys split the candy? In our case, it'd like to be going one by one and fill up the groups separately. You have to pick 3 out of 10 candies. You don’t want to bother with the order, so you declare the first 3 belong to A,
the next 3 belong to B and the last 3 belong to C - so in alphabetical order. Again, it doesn’t matter if C or B gets candies first. It’s just supposed to help us solve the problem. Since you don't care about the order of chosen candy for A, you can say you have 10 ways to choose 3 candies for A. It doesn’t matter if person A eats M&Ms or Skittles first, they only care that they have them. So there should be 10 choose 3 ways to give them candy.
Now, the rest of the group is left with the 7 remaining candies. B comes along AND you pick 3 out of the seven candies. So now we multiply by 7 choose 3. We'd repeat this process until we reach the last group. In our case just person C remains, where we multiply by the last 4 choose 3. In the end the answer should be: 16 800 ways. If we have a total of n items and each group has a capacity of c_1, c_2, and so on, we can
calculate it like so. [Generalize the formula.] This formula could be further improved with additional tweaks, for example this nasty bracket is the capacity of the remaining blocks. That’d be this blue block in this scenario. So we can write c_r (capacity of remaining), instead of this bracket. Sometimes we don’t have any remaining blocks, so we can express its capacity as zero. Here’s the cool part: this formula is essentially the same as the generalized permutation formula.
Why? Because in generalized permutations, we are allocating distinct items to distinct positions or, equivalently, assigning items to specific groups. Whether you think of it as “which candy goes to which friend” or “who owns which candy,” the counting works out the same. So we can mostly use either generalized permutations or generalized combinations, since they go hand in hand. Why the formulas are the same is something you can think about more yourself, but not now. I bet you're interested in the… Multinomial Theorem So let's talk about (a+b+c+d)^15, for example, and we want to know the coefficient of a^3b^2c^6d^4.
We should check if the exponents add up to 15, like with the binomial theorem problems. I'll tell you that it does. Let's imagine dividing the fifteen brackets into four groups. Group of brackets that contribute an "a", "b", "c", or "d". We know we should contribute to each group the same number of times as its exponent. So, only three brackets should go to Group A and two to Group B, and so on. Essentially, those are our capacities.
We can use our general combination formula to get the multinomial coefficient of that term. \binom{15}{3} [Show calculation] These give us the combinations of adding brackets to group A, group B, group C, and group D. Calculating this, we get 15!/3!2!6!4!. That equals 6,306,300 ways - our multinomial coefficient. So if we were to expand (a+b+c+d)^15, we'd find 6306300 a^3b^2c^6d^4. Repeatable permutations and variations You may have noticed that the main limitation
of the formulas is the fact that we assume all elements appear a limited number of times. What if we want to assume we have an infinite quantity of each element? If we select or allocate an element. We can allocate or select the same element again as if it magically appeared in the deck. How would that change the overall formula? First, let's talk about permutations. Whatever we pick, we have the same number of remaining options to select or allocate. If we go with the idea that we can pick the same number of elements as there are spaces, then, if we have n items, we should select them n times. Although this time we don't multiply our way from n to 1, we multiply the variable n n times. That gets us n^n. Variations are the same, but we don't select n times; instead, we select any amount of picks. Let's call that number p. So we have n options for p times. So we multiply n by itself p times. So we get n^p. Can we obtain
a similar formula for combinations, as well? Repeatable combinations - balls and urns Combinations with repetitions are where it gets interesting. Imagine you are ordering 12 ice creams and have to choose from 5 flavors. It doesn't matter how you order them, but it does matter how many of each flavor you have. You can order multiple of the same flavour. How many different orders can you have? Firstly, we imagine the 12 slots of the ice creams. Whatever ice cream flavors we pick, we should sort them. For example,
let's say. Chocolate flavours are first, followed by the vanilla and the other flavors. We don't care about the order, but the idea. It'd be helpful to find where the chocolate flavors stop and where vanilla flavors start, since that can change from order to order, right? How do we get that information here? Visually, we can create a divider between the different flavors. The first section will always be chocolate, then vanilla, and so on. If there were to be two dividers right next to each other, then we know there's no ice cream of that flavour. Currently, the dividers are in separate locations, but how about adding slots for them? We'd now have 12 + the number of dividers of slots. Suppose we remove the ice creams and dividers. Notice that we can place the dividers randomly and determine the flavors of ice cream for each slot. The first section is always chocolate, so every ice cream up to the first divider is chocolate.
Since the dividers are indistinguishable, we can ignore their order. How about we select the divider amount from the 12+dividers slots, where the dividers will be located? That would be the combination of 12+dividers choosing dividers, right? We're almost there, but we need to know how many dividers there are. Well, we know the number of flavors. Let's imagine a rope we want to cut into five sections. You only need four cuts,
since each cut produces a new section, and we already start with one section of rope. Therefore, our calculation should be 12 + 4 choose 4. Or generally p+n-1 choose n-1, where there are p items to pick from n types. Again, you can modify the formula to serve a slightly different purpose, but we will stick with this one. Formula summaries So, we had a lot of formulas, right? Let's compare them. We have permutations, variations, and combinations.
Permutations use all items and care about order, while variations allow us to use any amount. Combinations allow any amount as well, but we don't care about the order. However, each one of these formulas has a simple, general, and repeatable formula. We will conclude this chapter with this table and proceed to the Pigeonhole Principle. The Pigeonhole principle Fans of my channel are already familiar with this concept since it's among my favorite topics in discrete math. I've already made a video about it, but briefly: If we have n+1 pigeons flying into n pigeonholes, we are guaranteed that one of the pigeonholes will contain at least two pigeons. More generally, if k*n+1 pigeons fly into n pigeonholes. You are guaranteed to have at least one pigeonhole with k+1 pigeons
in it. That sounds obvious. If not, I've created a very detailed video on my channel. Please be sure to check that video out when in doubt. Though what makes this principle special, through its simplicity, is the fact that it is a powerful tool for proofs. It helps you reach conclusions you would typically need surveys for. For example, I can guarantee that there are at least two people in New York City with the same amount of hair, using this principle. A human can have 0 up to 150,000 strands of hair and the population of New York City is about 8.5 million. The number of hairs is our pigeonholes, and the population is the pigeons.
There are at least 57 people with the same amount of hair. The trick is to find out how many times the population exceeds the number of categories. In our case, it's above 56. This 56 would essentially work as our k in the definition of the pigeonhole principle. So, 56*150,000 + 1 people divided among 150,000 groups, based on their hair, ensures a group of at least 57 people with the same number of hair. We can prove something more interesting as well.
Did you know that in a group of 6 people, you are sure to have either a group of 3 people who know each other or a group of 3 people who are all strangers to each other? Imagine you are one of the people. Since you see a group of five people who know or don't know you, you are sure to have at least three people who belong to the same "familiarity" category. Let's take those people aside and examine the relationships between you and them. Red means unfamiliar, and blue means familiar. If I draw this diagram, it seems as if there is a familiarity between these two people; it'd make a triangle, which is our group of 3. Let's instead try to avoid it by saying they don't know each other. We'd have to do this between the remaining edges, but doing so creates a bigger triangle of unfamiliarity. It's the same if you had people you didn't know instead. Using the pigeonhole principle, we proved something about a set of numbers that have
yet to be discovered completely. For example, we don't know how many people we need to guarantee a group of 5 that consists of those who exclusively know or don't know each other. Another helpful tool aside from the Pigeonhole principle is PIE. No, not the cake nor the constant, but… The Principle of Inclusion-Exclusion (PIE) I hope you are familiar with the Venn diagram. All the points that are in this circle belong to set A, and outside of it don't. The same goes for set B. Some points are under multiple circles. Let's say we want to count the number of points. If we know the number of points that are in set A and set B, we can add them together, right? Well, not quite. Look at the middle points that are in both sets. You added them twice to the total count, even though they only appear once. Instead, we have to subtract the number of points between
them. If you count them twice, then subtracting the amount between them prevents you from counting the points in the middle twice. Let's count on this example. How many points are there? [Insert explanation of calculation] This might sound overly complicated, but it helps us generalize this for other types of problems. Let's try having more circles now. In each area, I'll add how many times it was counted. Add all the sets. We can see that we need to subtract the overlaps of two circles. Doing that leaves us with zero on the intersection of all three circles. Therefore, we need to add them to the final count to correct the issue. So we added, subtracted, added. This pattern continues forever. Adding can be understood as including the set, and subtracting as excluding elements from it. Thus, the Inclusion-Exclusion principle perfectly sums up its name.
For example, let's imagine this scenario: At a summer camp, students can sign up for three workshops — Photography, Robotics, and Drama. Thirty students signed up for Photography. Twenty-five students signed up for Robotics. Twenty students signed up for Drama. 12 signed up for both Photography and Robotics. 8 signed up for both Photography and Drama. 6 signed up for both Robotics and Drama. 4 signed up for all three workshops. The question is: How many students are there in total?
I'll put the problem aside for a moment and draw a Venn diagram to help visualize it. Here are circles for Photography, Robotics, and Drama. So far, we haven't counted any numbers in the diagram yet. Let's start by adding the number of students in each workshop: Photography has 30 students, Robotics has 25, and Drama has 20. When we add these numbers, we're counting every student in their respective workshops — but some students are counted more than once because they signed up for multiple workshops. Next, we subtract the students in the two workshops: 12 for Photography & Robotics, 8 for Photography & Drama, and 6 for Robotics & Drama. By subtracting these, we eliminate the double counting of students who signed up for exactly two workshops. However, when we subtract these pairs, the students who signed up for all three workshops end up being subtracted too many times. In fact, after this subtraction,
the triple-overlap region counts as zero — meaning those students aren't counted at all. That's why we add the number of students in all three workshops — which is 4 — back once, to include them correctly. Putting it all together, the total number of students is: 30+25+20−12−8−6+4=53 Now that we've seen how powerful the Principle of Inclusion-Exclusion is, we can use it to explore some other fascinating concepts in combinatorics. One of those concepts is derangements.
Derangements Sometimes you ask yourself, "How can I mess that up?" Well, derangements would give you that answer. You may have envelopes with their respective messages. You don't want to put each message into an envelope. Instead, you do it at random. Maybe John's message gets delivered to Margret. We want to pull a prank and hope everyone gets a wrong message. How many different ways could I mix it up so no one gets their original message? So in other words, how probable is it when randomly mixing? The answer lies in Derangements. All the possible mixing shouldn’t be a concern since we take the messages as they come into our hands, but some of those mixes might be partially correct. We don't want that. We know that the number of derangements is the difference between the number of permutations and the cases where any message reaches its intended recipient. We write
derangements similarly to factorials, but instead we put the exclamation mark before the variable. So, !n = n! - c, where c is the number of partially correct cases. How do we find how many of c there are? Let's discuss. Firstly, let's draw a Venn diagram for all the permutations. The cases contained in this box should be n!, but we need to divide the set into subsets, where some person gets the correct letter. For example, this will be our circle for "Person A got the right letter." Now we add the rest. For now, we will suffice with A, B, and C. Now we need to find the number of scenarios between them using the principle of inclusion and exclusion. Let's start like this: How many ways can we fix a letter to its rightful recipient? We have n people (currently 3) and we're choosing one. So
n choose 1. We just need to choose an owner You now have the remaining letters to mix and match. In each of those combinations, you have (n-1)! ways to mix up the rest. You might be asking yourself if the mixing won't include a permutation where two letters are fixed correctly. That is possible, but that's why we use the principle of inclusion and exclusion so to ensure that the permutation is counted only once. We add this term, based on the principle of inclusion and exclusion. Now that we've counted all the permutations with one letter correct, let's move to 2 letters being correct. We need to pick 2 out of n recipients. So
n choose 2. The rest of the letters will be permuted amongst themselves so (n-2)! Since we added our previous term, we have to subtract this one. Remember inclusion-exclusion. We would continue until we had to choose more fixed letters than there were envelopes. So our last term has to be n choose n times (n-n)! We don't know if the last term is positive or negative; it depends on what n is, when considering inclusion and exclusion. Now, this expression isn't exactly clean. Can we make the terms somehow easier? If we
examine one of these terms, we can rewrite the combination number in factorial form and cancel out the (n-k)! So, each term is, in fact, n! over the factorial of a number. Thus, our whole expression is n!/1! - n!/2! + n!/3! etc. This expression totals the number of permutations of letters that are at least partially correct for n letters and envelopes. Let's remind ourselves what we needed this for: The number of derangements is the difference
between the number of permutations and the number of partially correct cases. Now that we know how many cases are partially correct, we can substitute that for c; thus, we get this expression: !n = n! - (n!/1! - n!/2! + n!/3! …). Now we remove it from the brackets and we can factor out n! from the right side to get this expression: n! (1 - 1/1! + 1/2! - 1/3! + …) There's this nasty string of numbers over there that can be approximated. There's a number - a constant, to be exact - whose powers can be approximated. E is Euler's constant, and this long expression can approximate e to the power of x. (1+x/1!+x/2!+x/3!...) You can notice that both expressions share the factorials in the denominators. Though you might argue, there are these powers of x and not negatives compared to the original. Well, we can substitute for x, but the question is. What x can we use to get the expression above?
Firstly, we want to get ones in the numerators instead of x, that means we can substitute 1 for x. Since 1 to any power is one, we almost get the same expression. We only need to get the negatives there. Ok, let's try again. What if we substitute a negative number instead? Negative numbers raised to odd powers will be negative, and those raised to even powers will be positive. That would help us create that pattern of plus and minus. AHA! How about we use both?
A negative number and a one? X = -1? Substituting that produces the exact pattern we have above. Now we know that this pattern is approximately e to the power of -1, that is, 1 over e, where e is approximately 2.718. The problem is the number of terms in the expression, because that determines the accuracy of our approximation. However, we can discuss these expressions further at another time. I'll reveal that this approximation is more than 99% accurate for n>5.
Now we have both the original formula and the approximation. An interesting fact that stems from the approximation is that derangements have roughly the same probability regardless of the number of items to be deranged. If I divide n! on both sides, I get !n/n!, which means the ratio between derangements and permutations. Notice that the right side is just a number. One over e is approximately 0.368, which is equivalent to 36.8%. Putting that into real life perspective, if you randomly match definitions to answers on a school test, there's always about a 36.8% chance that none are correct — and about a 63.2% chance that at least one is correct. This fact applies to a large enough number of definitions and answers,
and remains unchanged even when we add more questions. Quite inspiring for upcoming tests. And that's where we'll stop for today. We've progressed from the basics of sets to the fascinating tools of combinatorics. There's always more for you to learn. I have a number of similar videos on my YouTube channel, such as this one about the Pigeonhole principle, which includes a simulation. Or you could learn a new topic. For example, Stirling numbers, which help you divide people into groups without caring about the size of those groups. Or even Catalan numbers - a mysterious sequence that comes up seemingly at random in several combinatorial problems. You could look into those, or I'll discuss them one day as well. Currently, I want to continue exploring combinatorics and investigate generating functions to see how they can help us count. Make sure to subscribe to stay tuned for more math content coming your way

Ask anything
We've read this whole study set, so questions about it get the best answers.