⭐ String / Array rearrangement terms

TermMeaningExample
PermutationRearrangement of same elementsabc → bac
CombinationChoose elements, order doesn’t matter{1,2} same as {2,1}
AnagramString permutation (same chars, diff order)listen → silent
SubsequenceKeep order, can skip charsace from abcde
SubstringContinuous part of stringbcd from abcde
SubarrayContinuous part of array[2,3] from [1,2,3,4]
SubsetAny selected elements{1,3} from {1,2,3}

⭐ Super important distinctions (easy to confuse) 📌

Often confusedDifference
Substring vs Subsequencecontinuous vs can skip
Subset vs Subarrayany elements vs continuous
Permutation vs Combinationorder matters vs not

⭐ Permutation vs Combination

1️⃣ Permutation = Arrange

When order matters.

From {A,B,C}, pick 2:

  • AB
  • BA
  • AC
  • CA
  • BC
  • CB

AB ≠ BA

So different order = different answer.

**Formula

P(n,r) = n!  /  (n-r)!

Example:

P(3,2) = 6

Used in:

  • Arrange numbers
  • Generate sequences
  • Next permutation
  • Anagrams / string rearrangement

2️⃣ Combination = Choose

When order does NOT matter.

From {A,B,C}, choose 2:

  • {A,B}
  • {A,C}
  • {B,C}

{A,B} = {B,A}

Same group.

Formula

C(n,r) = n! / r! (n-r)!

Example:

C(3,2) = 3

Used in:

  • Select team members
  • Pick subsets
  • Combination sum
  • Choose k elements

3️⃣ Easy Memory Trick 📌

Permutation = Position / Arrange
→ order matters

Combination = Collect / Choose
→ order doesn’t matter


Quick check

From {1,2,3}, pick 2:

Permutation

  • 12
  • 21
  • 13
  • 31
  • 23
  • 32

Combination

  • {1,2}
  • {1,3}
  • {2,3}