Panda Guru LogoPanda
Guru

Permutation vs Combination Basic theory

Permutation vs Combination Basic Theory

Let's break it down in a simple way with examples.


Permutation vs Combination

Both permutation and combination are ways to select items from a group, but:


1. Permutation (Order Matters)

If you have N items and you want to pick R items where order matters

Example:

You have A, B, C, and you want to select 2 letters in different orders.

Possible selections:
AB, BA, AC, CA, BC, CB (Different order matters!)


2. Combination (Order Doesn’t Matter)

If you have N items and you want to pick R items where order does NOT matter

Example:

You have A, B, C, and you want to select 2 letters, but order doesn’t matter.

Possible selections:
AB, AC, BC (Here, AB is the same as BA)


How This Applies to LeetCode Coding Problems

  1. Use Permutations when order matters

    • Example: Generating all possible orderings of a list ([1,2,3][1,2,3], [1,3,2], [2,1,3] etc.)
    • LeetCode problem: "Permutations" (Backtracking)
  2. Use Combinations when order does NOT matter

    • Example: Picking subsets ([1,2,3]{1,2}, {1,3}, {2,3})
    • LeetCode problem: "Combinations" (Backtracking)

When to Use Which?


Quick Mnemonic
👉 Permutation = Position matters
👉 Combination = Choice matters, but order doesn't