⭐ String / Array rearrangement terms
| Term | Meaning | Example |
|---|---|---|
| Permutation | Rearrangement of same elements | abc → bac |
| Combination | Choose elements, order doesn’t matter | {1,2} same as {2,1} |
| Anagram | String permutation (same chars, diff order) | listen → silent |
| Subsequence | Keep order, can skip chars | ace from abcde |
| Substring | Continuous part of string | bcd from abcde |
| Subarray | Continuous part of array | [2,3] from [1,2,3,4] |
| Subset | Any selected elements | {1,3} from {1,2,3} |
⭐ Super important distinctions (easy to confuse) 📌
| Often confused | Difference |
|---|---|
| Substring vs Subsequence | continuous vs can skip |
| Subset vs Subarray | any elements vs continuous |
| Permutation vs Combination | order matters vs not |
⭐ Permutation vs Combination
1️⃣ Permutation = Arrange
When order matters.
From {A,B,C}, pick 2:
ABBAACCABCCB
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
kelements
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
122113312332
Combination
{1,2}{1,3}{2,3}