Course 4.1Lesson 1 of 3
When a choice is made in stages, one after another, multiply the numbers of choices at each stage. With ways for the first stage and ways for the second, there are outcomes. A tree diagram shows why. When repetition is allowed, every stage keeps all its choices. When it is not, each stage has one choice fewer than the stage before.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
Neel packs for a school trip. He has shirts, white, blue and green, and pairs of trousers, black and grey. How many different outfits of one shirt and one pair of trousers can he wear?
You could list them all: white with black, white with grey, blue with black, and so on. A tree diagram lists them in order. It branches once for the shirt, and then once more for the trousers.
There are ends to the tree, so there are outfits. Look at how the tree is built. Each of the shirts has branches after it. So the number of ends is .
Listing works for outfits. It does not work for a million number plates. We need a rule that counts without listing.
The fundamental principle of counting. Suppose one event can happen in different ways, and after it a second event can happen in different ways. Then the two events, one after the other, can happen in ways.
The rule extends to any number of stages. With , and ways for three events in turn, there are ways in all.
Add pairs of shoes to Neel's bag. Each of his outfits can go with either pair, so he now has outfits.
The rule needs one condition. The number of ways for the second stage must be the same, whatever happened at the first stage. In the tree, every branch must split into the same number of new branches.
A mobile phone asks for a -digit PIN. Each digit is one of the digits to .
So the words "with repetition" and "without repetition" change the count a great deal. Read them carefully in every question.
Many counting questions ask you to fill a row of places. Draw a box for each place. Write in each box the number of ways to fill it, and multiply.
Example. A flag has three horizontal strips, each of a different colour. There are colours to choose from. How many different flags can be made?
So there are flags. Red, white, green from top to bottom is a different flag from green, white, red, so the order of the strips matters here.
A state makes number plates with different letters, then digits. The digits may repeat. How many plates can it issue?
The state could never list them all. The principle counts them in four lines.
The program lists every outfit with itertools.product, which takes one item from each list in every possible way. Then it counts the list, and compares with the product of the three sizes.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…