Programming Terms: Combinations and Permutations
Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Use combinations when the order of selected items does not create a new outcome; treat rearrangements as equivalent.
Briefing
Combinations and permutations differ in one crucial way: whether the order of selected items matters. A combination counts groups where rearranging the same values doesn’t create a new result; a permutation counts every distinct ordering as a separate outcome. That distinction shows up constantly in computer science, from search and constraint problems to word and pattern matching.
Using Python’s iter tools module, the examples start with a list [1, 2, 3] and groups of size 3. With combinations, only one group appears—[1, 2, 3]—because any other ordering like [3, 2, 1] represents the same set of values when order is ignored. When the group size drops to 2, combinations produce three groups: [1, 2], [1, 3], and [2, 3]. Notably, the reverse orderings (like [2, 1]) don’t appear because they don’t count as new combinations.
Switching to permutations with the same list and group size 2 changes the output. The same value pairs now appear in both orders: [1, 2] and [2, 1], [1, 3] and [3, 1], [2, 3] and [3, 2]. The key takeaway is that permutations treat different orderings as distinct, while combinations treat them as equivalent.
The practical importance comes down to how a problem is worded and what “counts” as a different answer. For a combinations-friendly scenario, the transcript uses a list of six numbers [1, 2, 3, 4, 5, 6] and asks for groups of three whose sum equals 10. With combinations, the results are limited to sets of values that add to 10, such as [1, 3, 6] (sum 10), [1, 4, 5] (sum 10), and [2, 3, 5] (sum 10). The ordering doesn’t matter because the question only cares about which numbers are included, not the sequence.
Replacing combinations with permutations for the same “sum equals 10” task produces many more results, including cases like [6, 3, 1] that are effectively the same as [1, 3, 6] under an order-insensitive interpretation. That mismatch illustrates why combinations are usually the right tool when the task is about selecting values that satisfy a condition.
For a permutations-friendly scenario, the transcript builds a simple word-matching game. Given a sample word, it checks whether any arrangement of its letters can form the target word. Here, combinations fail because they collapse different orderings into one group, missing valid rearrangements. Permutations succeed because they enumerate every possible ordering of the letters; once the correct sequence appears, the joined letters match the target word.
Finally, the transcript flags a performance concern: permutations grow extremely fast as the number of items increases, which can quickly consume computing power. The practical rule is straightforward—use combinations when order doesn’t matter, and use permutations when order is part of the answer.
Cornell Notes
Combinations count groups of items where order doesn’t matter; permutations count arrangements where order does matter. In the examples, combinations of [1,2,3] taken two at a time yield [1,2], [1,3], and [2,3], while permutations also include reversed orders like [2,1] and [3,1]. A sum-based constraint problem (groups of three that add to 10) fits combinations because [1,3,6] and [6,3,1] represent the same selected values. A word-matching task fits permutations because only the correct ordering of letters produces a match. Permutations can also explode in size as more items are added, so they’re computationally heavier.
How can you tell whether a problem should use combinations or permutations?
Why do combinations produce fewer results than permutations in the examples?
What does the “sum equals 10” example demonstrate about combinations?
Why does the word-matching game require permutations?
What computational risk comes with permutations?
Review Questions
- Given a list of numbers and a requirement like “choose 3 numbers whose sum is 12,” which should be used—combinations or permutations—and why?
- If a task asks whether any arrangement of letters can form a specific word, what method fits best and what failure mode occurs with combinations?
- How does the output change when you switch from combinations to permutations for the same list and group size?
Key Points
- 1
Use combinations when the order of selected items does not create a new outcome; treat rearrangements as equivalent.
- 2
Use permutations when the order matters and different sequences count as distinct answers.
- 3
A sum-based constraint problem typically matches combinations because only the selected values matter, not their arrangement.
- 4
A word or sequence-matching problem typically matches permutations because the exact ordering determines success.
- 5
Permutations can increase output size dramatically as the number of items grows, which can strain computation.
- 6
Python’s iter tools module provides built-in combinations and permutations so programmers don’t need to implement them from scratch.