7.4 Tree Diagrams, Tables, and Outcomes

In the 19th century, an Augustinian friar and scientist named Gregor Mendel used his observations of pea plants to set out his theory of genetic propagation. In his work, he looked at the offspring that resulted from breeding plants with different characteristics together. For applications like this, it is often insufficient to only know in how many ways a process might end; we need to be able to list all of the possibilities. As we’ve seen, the number of possible outcomes can be very large! Thus, it’s important to have a strategy that allows us to systematically list these possibilities to make sure we don’t leave any out. In this section, we’ll look at two of these strategies.
Single Stage Experiments
When we are talking about combinatorics or probability, the word “experiment” has a slightly different meaning than it does in the sciences. Experiments can range from very simple (“flip a coin”) to very complex (“count the number of uranium atoms that undergo nuclear fission in a sample of a given size over the course of an hour”). Experiments have unknown outcomes that generally rely on something random, so that if the experiment is repeated (or replicated) the outcome might be different. No matter what the experiment, though, analysis of the experiment typically begins with identifying its sample space.
from itertools import product
from fractions import Fraction
# A multistage experiment: flip a coin, then roll a die. The tree has two
# levels; this is the same information as a table you can read straight through.
# EDIT these two: use nonempty lists of distinct choices within each stage.
# Choices may be letters, numbers or whole words; counts are derived from them.
stage1 = ["H", "T"]
stage2 = [1, 2, 3, 4, 5, 6]
# Repeated labels would count the same named outcome more than once.
for name, choices in (("stage1", stage1), ("stage2", stage2)):
if not choices:
raise ValueError(f"{name} must be nonempty: include at least one choice.")
if len(set(choices)) != len(choices):
raise ValueError(f"{name} must contain distinct choices: remove repeated labels.")
space = list(product(stage1, stage2))
print(f"sample space: {len(stage1)} x {len(stage2)} = {len(space)} outcomes")
print()
# Ordered pairs keep the two stages separate, even with multiword choices.
table = [["stage 1 / stage 2"] + [repr(d) for d in stage2]]
for face in stage1:
table.append([repr(face)] + [repr((face, d)) for d in stage2])
widths = [max(len(row[i]) for row in table) for i in range(len(table[0]))]
for row in table:
print(" | ".join(cell.ljust(width) for cell, width in zip(row, widths)))
print()
p = Fraction(1, len(space))
print("Assume the stages are independent and each listed choice is equally likely.")
print(f"Then every outcome has probability {p}.")
# An EVENT is a grouping of outcomes, so its probability is just a count.
# The events are DERIVED from whatever the two stages now hold, so they stay
# meaningful after an edit instead of silently describing the old experiment.
first, last = stage1[0], stage2[-1]
events = {
f"first stage is {first}": lambda a, b: a == first,
f"second stage is {last}": lambda a, b: b == last,
f"first is {first} AND second is {last}": lambda a, b: a == first and b == last,
f"first is {first} OR second is {last}": lambda a, b: a == first or b == last,
}
print()
for name, rule in events.items():
hits = [o for o in space if rule(*o)]
print(f" P({name:<34}) = {len(hits)}/{len(space)} = {Fraction(len(hits), len(space))}")
print()
print(f"Adding another first-stage draw multiplies the number of outcomes by {len(stage1)}.")
print("The product counts the branches without listing every outcome.")
from math import prod
for stages in (2, 3, 4):
sizes = [len(stage1)] * stages + [len(stage2)]
print(f" {stages} draws from the first stage ({len(stage1)} choices) then one "
f"from the second ({len(stage2)}): "
f"{' x '.join(str(s) for s in sizes)} = {prod(sizes)} outcomes")The sample space of an experiment is the set of all of the possible outcomes of the experiment, so it’s often expressed as a set (i.e., as a list bound by braces; if the experiment is “randomly select a number between 1 and 4,” the sample space would be written ).
Multistage Experiments
Some experiments have more complicated sample spaces because they occur in stages. These stages can occur in succession (like drawing cards one at a time) or simultaneously (rolling 2 dice). Sample spaces get more complicated as the complexity of the experiment increases, so it’s important to choose a systematic method for identifying all of the possible outcomes. The first method we’ll discuss is the table.
Using Tables to Find Sample Spaces
Tables are useful for finding the sample space for experiments that meet two criteria: (1) The experiment must have only two stages, and (2) the outcomes of each stage must have no effect on the outcomes of the other. When the stages do not affect each other, we say the stages are independent. Otherwise, the stages are dependent and so we can’t use tables; we’ll look at a method for analyzing dependent stages soon.
If you have a two-stage experiment with independent stages, a table is the most straightforward way to identify the sample space. To build a table, you list the outcomes of one stage of the experiment along the top of the table and the outcomes of the other stage down the side. The cells in the interior of the table are then filled using the outcomes associated with each cell’s row and column. Let’s look at an example.
Using Tree Diagrams to Identify Sample Spaces
In experiments where there are more than two stages, or where the stages are dependent, a tree diagram is a helpful tool for systematically identifying the sample space. Tree diagrams are built by first drawing a single point (or node), then from that node we draw one branch (a short line segment) for each outcome of the first stage. Each branch gets its own node at the other end (which we typically label with the corresponding outcome for that branch); from each of these, we draw another branch for each outcome of the second stage, assuming that the outcome of the first stage matches the branch we were on. If there are other stages, we can continue from there by continuing to add branches and nodes. This sounds really complicated, but it’s easier to understand through an example.
Key Terms
- experiment
- replication
- sample space
- independent/dependent
Key Concepts
- We identify the sample space of an experiment by identifying all of its possible outcomes.
- Tables can help us find a sample space by keeping the possible outcomes organized.
- Tree diagrams provide a visualization of the sample space of an experiment that involves multiple stages.
Adapted from Contemporary Mathematics by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.