β 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 |
| 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} |
| Subsequence | Keep 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]
| Term | Order 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,CBAB β 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,2113,3123,32Combination (order doesnβt matter):
{1,2}{1,3}{2,3}