Counting and Probability for Code
-
Counting Disjoint Cases
Add the numbers of outcomes in cases that cover the goal without overlap. Identify double counting before applying the rule.
-
The Multiplication Rule for Successive Choices
When each allowed first choice has the same number of second choices, the product counts complete ordered outcomes.
-
Ordered Choices Without Replacement
When selected items cannot be reused, each selection in an ordered sequence reduces the number remaining.
-
Counting Unordered Combinations
Count selections of distinct items without assigning an order to the chosen group.
-
Pascal's Recursion for Combinations
Subsets of a specified size can be separated into those containing a distinguished item and those that omit it.
-
When Counting Outcomes Gives a Probability
Dividing favorable outcomes by a total is valid when the outcomes form a finite set of equally likely possibilities.
-
Using the Complement to Find a Probability
Finding the probability that an event never happens can be easier than directly counting every way it happens at least once.
-
Conditional Probability as a Restricted Count
Conditioning restricts attention to outcomes where the supplied event occurred. The original probabilities must be renormalized over that restriction.
-
Independence and Mutual Exclusion
Independent events satisfy a product rule for their intersection. Disjoint events have no common outcome.
-
Probability in Sampling Without Replacement
Taking an item out changes the available population and can alter the probability of later draws.
-
Total Probability by Partitioning into Groups
A total event probability can be computed as a weighted sum of its probabilities within disjoint groups covering the population.
-
Bayes' Rule from a Small Frequency Table
Bayes' rule reverses a conditional question by recalculating the denominator for the observed result.
-
Expected Value as a Probability-Weighted Average
An expected value multiplies each numeric outcome by its probability and sums the products.
-
Indicators Turn Event Counts into Sums
An indicator is one when an event occurs and zero otherwise. Its expectation is exactly that event's probability.
-
Variance Using Two Possible Outcomes
Variance is the expected squared distance from the mean. Its value can distinguish outcomes with the same average and different spreads.
-
Bounding the Chance of Any of Several Events
The probability of at least one event is at most the sum of the individual probabilities, whether those events are independent or related.
-
A Small Binomial Probability
For independent trials with a shared success probability, enumerate each possible choice of successful positions to find the probability of a success count.
-
Expected Waiting Time for Independent Repeated Trials
With independent repeat trials and fixed success probability, the number of attempts until the first success has a geometric distribution on positive integers.
-
A Random Variable as a Function of Outcomes
A random variable assigns a number to each underlying outcome. Different outcomes can map to one result.
-
Representing a Discrete Distribution as Probabilities
A probability mass table associates each possible value with its probability. Entries are nonnegative and sum to one across the support.
-
Sampling with Cumulative Weights
Nonnegative weights can define consecutive intervals. Draw a uniform position in the total span and choose the interval covering it.
-
When to Enumerate and When to Simulate
Enumeration can give an exact finite probability. Simulation estimates the result by repeating samples from a defined model.
-
Choosing an Item Uniformly from a List
Selecting a uniform position gives equal probability to every position. Values repeated at several positions get greater total probability.
-
Estimating a Proportion from Observations
The observed fraction of successes estimates a probability under a sampling model. It retains information about sample count and variation.
-
Combining Group Rates with Unequal Sizes
Combine each group's numerator and denominator, or weight its rate by its size. The mean of rates answers a different weighting question.
-
Why Collision Opportunities Grow with the Number of Pairs
Each pair of independent uniform labels has a chance to match. The count of pairs grows faster than the count of labels drawn.
-
Counting Strings Over a Finite Alphabet
A string's positions give ordered choices. Constraints on length, repetition, or required symbols change the count.
-
Counting Shortest Monotone Grid Paths
A path taking only right and down steps is determined by the positions of one kind of step in its ordered move list.
-
Deterministic Replay of a Random Experiment
A recorded seed and a compatible generator can reproduce a pseudo-random sequence. The sequence of calls matters as much as the seed.
-
Sample Size and Apparent Fairness
A small run of a fair process can produce counts that look unequal. A useful check describes what variation the assumed process predicts.