⭐ 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
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}
SubsequenceKeep order{1,3} from {1,2,3}

Relationship

For an array:

arr = [1, 2, 3]

The subsets are: [], [1],, [2], [3], [1,2], [1,3], [2,3], [1,2,3]

TermOrder Preserved?Contiguous?
Subsetβœ… No mathematical order, but when represented from an array we preserve original order❌ No
Subsequenceβœ… Yes❌ No
Subarrayβœ… Yesβœ… Yes

⭐ Permutation vs Combination

1️⃣ Permutation = Arrange

When order matters.

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

  • AB, BA, AC, CA, BC, CB
  • AB β‰  BA (different order = different answer)

Formula:

Example:

2️⃣ Combination = Choose

When order does NOT matter.

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

  • {A,B}, {A,C}, {B,C}
  • {A,B} = {B,A} (same group = same answer)

Formula:

Example:


Quick Check πŸ”

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

Permutation (order matters):

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

Combination (order doesn’t matter):

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