Skip to main content

8.1 Counting Principles, Permutations, Combinations & Stars and Bars

πŸ“šModule 08: Combinatorics & Recurrence RelationsTopic 8.1: Counting Principles, Permutations & Stars and Bars⏱️5 min read
🎯High-Yield For:Semester Exams β€’ GATE CSE β€’ Technical Interviews

πŸ’‘ Core Intuition: The 3-Second Mental Model​

🍳 The Everyday Analogy: Fast Food Menus, Passwords & Coin Jars​

Think of counting as structuring choices in physical spaces:

  1. Rule of Sum (Mutually Exclusive Alternatives): You are buying lunch. You can pick either a burger from the 5 burger options OR a salad from the 3 salad options. Total independent meal choices: 5+3=85 + 3 = 8. In choice, you use addition (+).
  2. Rule of Product (Sequential Multi-Stage Choices): You are building a combo meal. You pick 1 of 5 burgers, AND 1 of 4 drinks, AND 1 of 3 sides. Total compound configurations: 5Γ—4Γ—3=605 \times 4 \times 3 = 60 unique meals! In mandatory sequential stages, you use multiplication (Γ—\times).
  3. Permutation vs Combination:
    • Permutation (Order Matters): Setting a 4-digit security PIN (1-2-3-4 is completely different from 4-3-2-1). Permutation = Choose and Arrange.
    • Combination (Order Irrelevant): Picking a 4-person study team (Alice, Bob, Charlie, Dave is the exact same team regardless of who you named first). Combination = Choose Only.
  4. Stars and Bars (Distributing Identical Candies): You have 10 identical gold coins (n=10n = 10) to drop into 3 piggy banks (r=3r = 3). You don't label the coins; you simply place 2 divider sticks (bars) between the 10 coins (stars). Any arrangement of stars and bars uniquely represents an integer partition!

πŸ’» Bridging to Computer Science: Address Spaces, Combinatorial Testing & State Spaces​

In computer systems:

  • IPv4 / IPv6 Address Spaces: Calculating address capacities uses the Rule of Product: an IPv4 address has 2Γ—2Γ—β‹―Γ—2=232β‰ˆ4.29Γ—1092 \times 2 \times \dots \times 2 = 2^{32} \approx 4.29 \times 10^9 unique host addresses.
  • Complexity Analysis: Measuring the search space of NP-complete problems (e.g., Travelling Salesperson has (nβˆ’1)!/2(n-1)! / 2 tours; Knapsack has 2n2^n subsets).
  • Resource Allocation in OS: Distributing nn identical buffer pages among rr active processes is the classical Stars and Bars problem.
  • Compiler Symbol Tables: Lexicographic indexing and keyword permutations determine dictionary search efficiency.

⚑ Fundamental Counting Principles​

⚑Law 8.1: The Two Foundational Counting Ruleslaw
  1. The Rule of Sum (Disjoint Unions - OR Rule): If a task can be performed in either of two mutually exclusive ways, where the first way has mm possible outcomes and the second way has nn possible outcomes (with no overlap): ∣AβˆͺB∣=∣A∣+∣B∣=m+n(providedΒ A∩B=βˆ…)|A \cup B| = |A| + |B| = m + n \quad (\text{provided } A \cap B = \emptyset)
  2. The Rule of Product (Cartesian Multi-Stage Execution - AND Rule): If a procedure can be broken down into two successive stages, where Stage 1 has mm possible choices, and for each choice in Stage 1, Stage 2 has nn possible choices: ∣AΓ—B∣=∣Aβˆ£β‹…βˆ£B∣=mβ‹…n|A \times B| = |A| \cdot |B| = m \cdot n
βœ“ Combinatorial Selection SpaceΓ· r! (Unorder)Stars & Bars+ RepetitionMultiset MapP(n, r)Ordered, No RepnΚ³Ordered, UnlimitedC(n, r)Unordered, No RepC(n+r-1, r)Stars & Bars
Vertical axis: Division by r! strips ordering; Horizontal axis: Multi-set expansion incorporates repetitions.

The 4 Fundamental Combinatorial Counting Archetypes

Matrix comparing ordered vs unordered selection with and without replacement

πŸ”’

Permutations (No Repetition)

Ordered, Distinct
  • Select and arrange r distinct items from n available items.
  • Formula: P(n, r) = n! / (n - r)!.
  • Example: Assigning 1st, 2nd, and 3rd place podium medals.
πŸ”„

Permutations (With Repetition)

Ordered, Multi-Set
  • Each of the r positions independently picks any of the n items.
  • Formula: nΚ³.
  • Example: Generating an r-digit numeric PIN using digits 0-9 (10Κ³).
🀝

Combinations (No Repetition)

Unordered, Distinct
  • Select r items from n distinct items where sequence does not matter.
  • Formula: C(n, r) = n! / (r! (n - r)!).
  • Example: Selecting a 5-card poker hand from a 52-card deck.
⭐

Combinations (With Repetition)

Stars and Bars
  • Select r items from n types where items of same type are indistinguishable.
  • Formula: C(n + r - 1, r) = C(n + r - 1, n - 1).
  • Example: Distributing identical jobs across CPU execution queues.

πŸ”€ Permutations with Repeated Elements (Multi-Sets)​

When arranging nn total objects where some objects are identical:

πŸ“Theorem 8.1: Multi-Set Permutation Formulatheorem

The number of unique permutations of nn objects where there are n1n_1 identical objects of type 1, n2n_2 identical objects of type 2, ..., and nkn_k identical objects of type kk (such that n1+n2+β‹―+nk=nn_1 + n_2 + \dots + n_k = n) is given by the Multinomial Coefficient:

(nn1,n2,…,nk)=n!n1! n2! n3! … nk!\binom{n}{n_1, n_2, \dots, n_k} = \frac{n!}{n_1! \, n_2! \, n_3! \, \dots \, n_k!}

Proof Intuition: If all nn objects were distinct, there would be n!n! arrangements. However, permuting the n1n_1 identical objects among themselves in n1!n_1! ways produces visually indistinguishable arrangements. By the Division Rule, we divide out all internal symmetries n1!n2!…nk!n_1! n_2! \dots n_k!.


🧩 Advanced Arrangement Paradigms: The String & Gap Methods​

Two standard arrangement constraints appear universally in competitive exams and interview questions:

The String Method vs The Gap Method

Handling 'always together' vs 'never together' constraints in linear seating

🧡

The String / Tie Method

Items MUST Be Together
  • Bundle all items that must stay together into a single composite super-unit.
  • Step 1: Arrange the remaining items along with the composite super-unit.
  • Step 2: Multiply by the internal permutations of the items inside the super-unit.
  • Formula: (Remaining Items + 1)! Γ— (Bundle Size)!
πŸͺŸ

The Gap Method

NO Two Items Together
  • Step 1: First arrange the unconstrained items in a row in m! ways.
  • Step 2: This creates m + 1 distinct empty gaps (including both ends).
  • Step 3: Select and arrange the k constrained items into these m + 1 gaps.
  • Formula: m! Γ— P(m + 1, k) (Valid if and only if k ≀ m + 1).
πŸ“Case Study: Seating 5 Boys and 4 Girls with Adjacency Constraintsexample

Let there be 5 boys (B1,…,B5B_1, \dots, B_5) and 4 girls (G1,…,G4G_1, \dots, G_4):

  1. No two girls sit together (Gap Method):
    • First arrange the 5 boys: 5!=1205! = 120 ways.
    • The boys create 5+1=65 + 1 = 6 gaps: _β€…β€ŠB1β€…β€Š_β€…β€ŠB2β€…β€Š_β€…β€ŠB3β€…β€Š_β€…β€ŠB4β€…β€Š_β€…β€ŠB5β€…β€Š_\_ \; B_1 \; \_ \; B_2 \; \_ \; B_3 \; \_ \; B_4 \; \_ \; B_5 \; \_.
    • Place the 4 girls into any 4 of these 6 gaps: 6P4=6Γ—5Γ—4Γ—3=360{}^6 P_4 = 6 \times 5 \times 4 \times 3 = 360 ways.
    • Total ways = 5!Γ—6P4=120Γ—360=43,2005! \times {}^6 P_4 = 120 \times 360 = 43,200 ways.
  2. No two boys sit together (Gap Method):
    • First arrange the 4 girls: 4!=244! = 24 ways.
    • The girls create 4+1=54 + 1 = 5 gaps: _β€…β€ŠG1β€…β€Š_β€…β€ŠG2β€…β€Š_β€…β€ŠG3β€…β€Š_β€…β€ŠG4β€…β€Š_\_ \; G_1 \; \_ \; G_2 \; \_ \; G_3 \; \_ \; G_4 \; \_.
    • Place the 5 boys into these 5 gaps: 5P5=5!=120{}^5 P_5 = 5! = 120 ways.
    • Total ways = 4!Γ—5!=24Γ—120=2,8804! \times 5! = 24 \times 120 = 2,880 ways.
  3. A particular pair of girls (G1,G2G_1, G_2) must always sit together (String Method):
    • Bundle G1,G2G_1, G_2 into a single composite unit: [G1G2][G_1 G_2].
    • Entities to arrange: 5 boys + 2 remaining girls + 1 composite unit = 8 entities.
    • External arrangements: 8!8! ways.
    • Internal permutations inside the bundle: 2!2! ways (G1G2G_1 G_2 or G2G1G_2 G_1).
    • Total ways = 8!Γ—2!=40,320Γ—2=80,6408! \times 2! = 40,320 \times 2 = 80,640 ways.
  4. A particular pair of girls (G1,G2G_1, G_2) must NOT sit together (Complementary Counting):
    • Total unrestricted arrangements of 9 people: 9!=362,8809! = 362,880.
    • Arrangements where G1,G2G_1, G_2 sit together: 8!Γ—2!=80,6408! \times 2! = 80,640.
    • Total ways = Totalβˆ’Together=9!βˆ’(8!Γ—2!)=282,240\text{Total} - \text{Together} = 9! - (8! \times 2!) = 282,240 ways.

πŸ”„ Circular Permutations & Symmetries​

Arranging items around a closed circle differs fundamentally from linear arrangements because circular rotations do not produce distinct arrangements.

πŸ“Theorem 8.2: Circular Arrangements & Flip Invariancetheorem
  1. Circular Permutation of nn Distinct Entities: Fixing 1 reference entity removes the nn rotational degrees of freedom: Pcircular(n)=n!n=(nβˆ’1)!P_{\text{circular}}(n) = \frac{n!}{n} = (n - 1)!
  2. Necklaces & Keyrings (Reflection / Flip Invariance): If a necklace can be flipped over, clockwise and counter-clockwise arrangements become identical mirror images: Pnecklace(n)=(nβˆ’1)!2P_{\text{necklace}}(n) = \frac{(n - 1)!}{2} With n1n_1 beads of color 1, n2n_2 of color 2, ..., nkn_k of color kk: PnecklaceΒ multi-set=(nβˆ’1)!2β‹…n1! n2! … nk!P_{\text{necklace multi-set}} = \frac{(n - 1)!}{2 \cdot n_1! \, n_2! \, \dots \, n_k!}
  3. The Circular Gap Method (Crucial Rule):
    • When the first group of mm items is arranged in a circle, it takes (mβˆ’1)!(m - 1)! ways.
    • Crucial Invariant: Once the first group is seated in the circle, the mm gaps between them become linearly distinct (each gap is indexed by the specific unique neighbors to its left and right).
    • Therefore, the second group of kk items is placed into the mm gaps in mPk{}^m P_k linear ways!
    • Total ways = (mβˆ’1)!Γ—mPk(m - 1)! \times {}^m P_k.
πŸ“Example: Circular Seating of 7 Girls and 6 Boysexample

Let 7 girls and 6 boys be seated around a circular table:

  1. No two boys sit together:
    • First seat the 7 girls around the circular table: (7βˆ’1)!=6!=720(7 - 1)! = 6! = 720 ways.
    • The 7 girls create 7 distinct gaps between them.
    • Seat the 6 boys into these 7 distinct gaps: 7P6=7!=5,040{}^7 P_6 = 7! = 5,040 ways.
    • Total ways = 6!Γ—7P6=720Γ—5,040=3,628,8006! \times {}^7 P_6 = 720 \times 5,040 = 3,628,800 ways.
  2. Boys and girls sit alternately (77 boys and 77 girls):
    • Seat 7 boys in circle: (7βˆ’1)!=6!(7 - 1)! = 6! ways.
    • Seat 7 girls in the 7 gaps: 7!7! ways.
    • Total ways = 6!Γ—7!=720Γ—5,040=3,628,8006! \times 7! = 720 \times 5,040 = 3,628,800 ways.

πŸ“– Lexicographic Word Rank & The Fast Factorial Trick​

The rank of a word is its 1-based index when all unique anagrams formed by its letters are sorted alphabetically in a dictionary.

Dictionary Rank Algorithms

Classical tree counting versus the rapid right-hand factorial formula

πŸ“š

Standard Lexicographic Counting

Branch-by-Branch
  • Sort all characters in alphabetical order.
  • Count all permutations starting with characters preceding the target's first letter.
  • Fix the matched letter and recursively count sub-branches.
  • Add +1 at the end for the word itself.
⚑

Fast Factorial Shortcut Trick

O(n) Direct Evaluation
  • Write the word. For each letter, count how many letters strictly to its RIGHT are alphabetically smaller.
  • Multiply each count by the corresponding descending factorial: (n-1)!, (n-2)!, ..., 0!.
  • For repeated letters, divide each term by the repeat factorials in the suffix.
  • Sum all products and add +1.
πŸ“Worked Example: Finding the Rank of 'SIPRON' (No Repetition)example

Target word: SIPRON (Length n=6n = 6). Alphabetical order of letters: I(1),N(2),O(3),P(4),R(5),S(6)I (1), N (2), O (3), P (4), R (5), S (6).

Applying the Fast Factorial Trick:

  1. Letter S: Letters to its right smaller than S: {I,P,R,O,N}\{I, P, R, O, N\} (Count = 5). Multiplier: 5!5!. β†’5Γ—5!=600\to 5 \times 5! = 600.
  2. Letter I: Letters to its right smaller than I: none (Count = 0). Multiplier: 4!4!. β†’0Γ—4!=0\to 0 \times 4! = 0.
  3. Letter P: Letters to its right smaller than P: {O,N}\{O, N\} (Count = 2). Multiplier: 3!3!. β†’2Γ—3!=12\to 2 \times 3! = 12.
  4. Letter R: Letters to its right smaller than R: {O,N}\{O, N\} (Count = 2). Multiplier: 2!2!. β†’2Γ—2!=4\to 2 \times 2! = 4.
  5. Letter O: Letters to its right smaller than O: {N}\{N\} (Count = 1). Multiplier: 1!1!. β†’1Γ—1!=1\to 1 \times 1! = 1.
  6. Letter N: Letters to its right smaller than N: none (Count = 0). Multiplier: 0!0!. β†’0Γ—0!=0\to 0 \times 0! = 0.
Rank=(600+0+12+4+1+0)+1=617+1=618\text{Rank} = (600 + 0 + 12 + 4 + 1 + 0) + 1 = 617 + 1 = 618
πŸ“Worked Example: Finding the Rank of 'SECRET' (With Repetition)example

Target word: SECRET (Length n=6n = 6). Letters: C(1),E(2),E(2),R(4),S(5),T(6)C (1), E (2), E (2), R (4), S (5), T (6). Repeats: EE appears 2 times.

  1. S: Smaller to right: {E,C,R,E,T}β†’{E,C,E}\{E, C, R, E, T\} \to \{E, C, E\} (Count = 3). Suffix has {E,C,R,E,T}\{E, C, R, E, T\} with two EE's: 3Γ—5!2!=3602=180\frac{3 \times 5!}{2!} = \frac{360}{2} = 180. (Wait: check letters to right: E, C, R, E: smaller than S are C, E, R, E β†’4\to 4 letters smaller!) Let's check strictly: E,C,R,EE, C, R, E are all smaller than SS. That is 4 letters! Term = 4Γ—5!2!=4802=240\frac{4 \times 5!}{2!} = \frac{480}{2} = 240.
  2. E: Suffix is CRETCRET. Smaller to right: CC (Count = 1). Suffix has no repeats (C,R,E,TC, R, E, T has one EE remaining): 1Γ—4!1!=24\frac{1 \times 4!}{1!} = 24. (Note: if both E's were in suffix, divide by 2!2!; here only one E remains, so divide by 1!1!). Term = 24/2!24 / 2! if counting both: since the current letter is EE, the suffix CRETCRET has one EE. So repeats = 1!1!. β†’1Γ—4!=24/2=12\to 1 \times 4! = 24 / 2 = 12 (if second EE counts).
  3. C: Suffix RETRET. Smaller to right: none (0). Term = 0.
  4. R: Suffix ETET. Smaller to right: EE (Count = 1). Term = 1Γ—2!=21 \times 2! = 2.
  5. E: Suffix TT. Smaller to right: none (0). Term = 0.
  6. T: Suffix empty. Term = 0.

Sum of terms = 240+12+0+2+0+0=254240 + 12 + 0 + 2 + 0 + 0 = 254.

RankΒ of ’SECRET’=254+1=255\text{Rank of 'SECRET'} = 254 + 1 = 255

πŸ”’ Digit Permutations & The Master Sum Formula​

πŸ“Theorem 8.3: Master Formula for Sum of All Formed Numberstheorem

Given nn distinct non-zero digits {d1,d2,…,dn}\{d_1, d_2, \dots, d_n\}, the sum of all nn-digit numbers formed using each digit exactly once without repetition is:

Sum=(nβˆ’1)!Γ—(βˆ‘i=1ndi)Γ—(111…1⏟nΒ ones)\text{Sum} = (n - 1)! \times \left( \sum_{i=1}^n d_i \right) \times (\underbrace{111\dots 1}_{n \text{ ones}})

Proof Derivation:

  • In an nn-digit number, each digit appears at each decimal position (units, tens, hundreds, ..., 10nβˆ’110^{n-1}) exactly (nβˆ’1)!(n - 1)! times.
  • The total contribution of all digits at a single decimal place is (nβˆ’1)!βˆ‘di(n - 1)! \sum d_i.
  • Summing across all place values: (nβˆ’1)!(βˆ‘di)[10nβˆ’1+10nβˆ’2+β‹―+100]=(nβˆ’1)!(βˆ‘di)(111…1⏟n)(n - 1)! \left( \sum d_i \right) [10^{n-1} + 10^{n-2} + \dots + 10^0] = (n - 1)! \left( \sum d_i \right) (\underbrace{111\dots 1}_{n})
πŸ“Example: Sum of All 4-Digit Numbers Formed from {2, 3, 4, 5}example

Digits: {2,3,4,5}\{2, 3, 4, 5\} (n=4n = 4).

  • (nβˆ’1)!=3!=6(n - 1)! = 3! = 6.
  • Sum of digits: 2+3+4+5=142 + 3 + 4 + 5 = 14.
  • Place multiplier: 11111111.
TotalΒ Sum=6Γ—14Γ—1111=84Γ—1111=93,324\text{Total Sum} = 6 \times 14 \times 1111 = 84 \times 1111 = 93,324

⭐ The Stars and Bars Theorem (Integer Partitions)​

The Stars and Bars method (also known as the Bose-Einstein distribution) counts the number of ways to distribute nn identical items into rr distinct containers.

πŸ“Theorem 8.4: Stars and Bars (Non-Negative vs Positive Integer Solutions)theorem
  1. Non-Negative Integer Solutions (xiβ‰₯0x_i \ge 0): The number of solutions to x1+x2+β‹―+xr=nx_1 + x_2 + \dots + x_r = n where xi∈N0x_i \in \mathbb{N}_0 is:

    (n+rβˆ’1rβˆ’1)=(n+rβˆ’1n)\binom{n + r - 1}{r - 1} = \binom{n + r - 1}{n}

    Visual Derivation: nn stars (⋆\star) and rβˆ’1r - 1 divider bars (∣|) give n+rβˆ’1n + r - 1 total positions. Choosing rβˆ’1r - 1 positions for the bars partitions the stars into rr distinct buckets.

  2. Strictly Positive Integer Solutions (xiβ‰₯1x_i \ge 1): The number of solutions to x1+x2+β‹―+xr=nx_1 + x_2 + \dots + x_r = n where xiβ‰₯1x_i \ge 1 is:

    (nβˆ’1rβˆ’1)\binom{n - 1}{r - 1}

    Derivation: Pre-allocate 1 item to each of the rr containers, leaving nβˆ’rn - r items to distribute freely with yiβ‰₯0y_i \ge 0: ((nβˆ’r)+rβˆ’1rβˆ’1)=(nβˆ’1rβˆ’1)\binom{(n - r) + r - 1}{r - 1} = \binom{n - 1}{r - 1}.

  3. General Lower Bounds (xiβ‰₯kix_i \ge k_i): Substitute yi=xiβˆ’kiβ‰₯0y_i = x_i - k_i \ge 0. The equation becomes:

    βˆ‘i=1ryi=nβˆ’βˆ‘i=1rki=nβ€²β€…β€ŠβŸΉβ€…β€Š(nβ€²+rβˆ’1rβˆ’1)\sum_{i=1}^r y_i = n - \sum_{i=1}^r k_i = n' \implies \binom{n' + r - 1}{r - 1}
πŸ“Case Study: Restricted Dice Sum Problem with Upper Boundsexample

Problem: Find the number of ways 3 standard 6-sided dice can yield a sum of 10. Equation: x1+x2+x3=10x_1 + x_2 + x_3 = 10 subject to 1≀xi≀61 \le x_i \le 6 for each die.

  1. Step 1: Total positive integer solutions (xiβ‰₯1x_i \ge 1): (nβˆ’1rβˆ’1)=(10βˆ’13βˆ’1)=(92)=9Γ—82=36\binom{n - 1}{r - 1} = \binom{10 - 1}{3 - 1} = \binom{9}{2} = \frac{9 \times 8}{2} = 36
  2. Step 2: Subtract violations where some die exceeds 6 (xiβ‰₯7x_i \ge 7):
    • Suppose Die 1 violates the constraint: x1β‰₯7x_1 \ge 7.
    • Set y1=x1βˆ’6β‰₯1y_1 = x_1 - 6 \ge 1. The equation becomes: y1+x2+x3=10βˆ’6=4(y1β‰₯1,x2β‰₯1,x3β‰₯1)y_1 + x_2 + x_3 = 10 - 6 = 4 \quad (y_1 \ge 1, x_2 \ge 1, x_3 \ge 1)
    • Number of solutions: (4βˆ’13βˆ’1)=(32)=3\binom{4 - 1}{3 - 1} = \binom{3}{2} = 3.
    • By symmetry, any of the 3 dice could violate: 3Γ—(32)=3Γ—3=93 \times \binom{3}{2} = 3 \times 3 = 9.
    • Note: Can two dice simultaneously violate? If two dice are β‰₯7\ge 7, sum β‰₯7+7+1=15>10\ge 7 + 7 + 1 = 15 > 10, which is impossible.
  3. Step 3: Apply Principle of Inclusion-Exclusion: ValidΒ Ways=(92)βˆ’3(32)=36βˆ’9=27\text{Valid Ways} = \binom{9}{2} - 3 \binom{3}{2} = 36 - 9 = 27

πŸ“ Geometric Combinatorics & Shortcuts​

πŸ“Theorem 8.5: Geometric Combinatorics Toolkittheorem
  1. Diagonals of an nn-sided Polygon: Connecting any 2 vertices gives a line segment ((n2)\binom{n}{2}). Subtracting the nn perimeter edges: Diagonals=(n2)βˆ’n=n(nβˆ’1)2βˆ’n=n(nβˆ’3)2\text{Diagonals} = \binom{n}{2} - n = \frac{n(n - 1)}{2} - n = \frac{n(n - 3)}{2}
  2. Intersections of Straight Lines: Given nn straight lines in a plane with no two parallel and no three concurrent: IntersectionΒ Points=(n2)\text{Intersection Points} = \binom{n}{2}
  3. Parallelograms in a Grid: Given a family of pp parallel lines intersecting another family of qq parallel lines: Parallelograms=(p2)Γ—(q2)\text{Parallelograms} = \binom{p}{2} \times \binom{q}{2}
  4. Collinear Points in a Plane: Given nn coplanar points where pp points are strictly collinear (and no other 3 are collinear):
    • Straight Lines Formed: (n2)βˆ’(p2)+1\binom{n}{2} - \binom{p}{2} + 1 (the pp points collapse to 1 single line).
    • Triangles Formed: (n3)βˆ’(p3)\binom{n}{3} - \binom{p}{3} (collinear points cannot form triangles).
  5. Round-Robin Tournament Matches: In a tournament of nn teams where each team plays every other team exactly kk times: TotalΒ Matches=kβ‹…(n2)=kn(nβˆ’1)2\text{Total Matches} = k \cdot \binom{n}{2} = k \frac{n(n - 1)}{2}
  6. Selection from Multi-Sets (Alphabet Selection): Given a multi-set of identical items An1Bn2…ZnkA^{n_1} B^{n_2} \dots Z^{n_k}, the number of ways to select one or more items is: Non-EmptyΒ Selections=(n1+1)(n2+1)…(nk+1)βˆ’1\text{Non-Empty Selections} = (n_1 + 1)(n_2 + 1) \dots (n_k + 1) - 1 (Subtract 1 for the empty selection where 0 items of each type are chosen).

πŸ“ Step-by-Step Worked Examples​

Example 1: Multi-Set Permutations of "MISSISSIPPI" Under Adjacency Restrictions​

Problem Statement: Find the number of unique arrangements of all letters in the word "MISSISSIPPI":

  1. With no restrictions.
  2. Such that all four 'S' letters appear together.
  3. Such that no two 'S' letters appear together.

Step-by-Step Solution: Letter counts: M=1,I=4,S=4,P=2M = 1, I = 4, S = 4, P = 2 (Total n=11n = 11).

  1. Part 1: Unrestricted Arrangements: Total=11!1!Γ—4!Γ—4!Γ—2!=39,916,8001Γ—24Γ—24Γ—2=39,916,8001,152=34,650\text{Total} = \frac{11!}{1! \times 4! \times 4! \times 2!} = \frac{39,916,800}{1 \times 24 \times 24 \times 2} = \frac{39,916,800}{1,152} = 34,650
  2. Part 2: All Four 'S' Together (String Method):
    • Bundle four S's into [SSSS][SSSS] (1 unit).
    • Remaining letters: M(1),I(4),P(2)β†’7M(1), I(4), P(2) \to 7 letters.
    • Total units = 1+7=81 + 7 = 8 units.
    Arrangements=8!1!Γ—4!Γ—2!Γ—1!=40,32024Γ—2=840\text{Arrangements} = \frac{8!}{1! \times 4! \times 2! \times 1!} = \frac{40,320}{24 \times 2} = 840
  3. Part 3: No Two 'S' Together (Gap Method):
    • First arrange the non-S letters: M(1),I(4),P(2)M(1), I(4), P(2) (7 letters). WaysΒ toΒ arrangeΒ non-SΒ letters=7!1!Γ—4!Γ—2!=5,04048=105\text{Ways to arrange non-S letters} = \frac{7!}{1! \times 4! \times 2!} = \frac{5,040}{48} = 105
    • These 7 letters create 7+1=87 + 1 = 8 gaps: _β€…β€ŠL1β€…β€Š_β€…β€ŠL2β€…β€Š_β€…β€ŠL3β€…β€Š_β€…β€ŠL4β€…β€Š_β€…β€ŠL5β€…β€Š_β€…β€ŠL6β€…β€Š_β€…β€ŠL7β€…β€Š_\_ \; L_1 \; \_ \; L_2 \; \_ \; L_3 \; \_ \; L_4 \; \_ \; L_5 \; \_ \; L_6 \; \_ \; L_7 \; \_
    • Choose 4 of these 8 gaps for the 4 identical S letters: (84)=8Γ—7Γ—6Γ—524=70\binom{8}{4} = \frac{8 \times 7 \times 6 \times 5}{24} = 70.
    • Total arrangements = 105Γ—70=7,350105 \times 70 = 7,350.

Example 2: Distributing Identical OS Memory Frames via Stars and Bars​

Problem Statement: An operating system has 15 identical memory frames to distribute among 4 processes (P1,P2,P3,P4P_1, P_2, P_3, P_4).

  1. In how many ways can the frames be distributed if a process is allowed to receive 0 frames?
  2. In how many ways can the frames be distributed if process P1P_1 must receive at least 2 frames, and every other process must receive at least 1 frame?

Step-by-Step Solution:

  1. Part 1: Non-Negative Integer Solutions (xiβ‰₯0x_i \ge 0):
    • Equation: x1+x2+x3+x4=15x_1 + x_2 + x_3 + x_4 = 15 with xiβ‰₯0x_i \ge 0.
    • Formula: (n+rβˆ’1rβˆ’1)=(15+4βˆ’14βˆ’1)=(183)=18Γ—17Γ—166=816\binom{n + r - 1}{r - 1} = \binom{15 + 4 - 1}{4 - 1} = \binom{18}{3} = \frac{18 \times 17 \times 16}{6} = 816 ways.
  2. Part 2: Lower-Bound Inequality (x1β‰₯2,x2β‰₯1,x3β‰₯1,x4β‰₯1x_1 \ge 2, x_2 \ge 1, x_3 \ge 1, x_4 \ge 1):
    • Pre-allocate the required frames: 2+1+1+1=52 + 1 + 1 + 1 = 5 frames.
    • Remaining frames to distribute freely: 15βˆ’5=1015 - 5 = 10 frames.
    • Transformed equation: y1+y2+y3+y4=10y_1 + y_2 + y_3 + y_4 = 10 with yiβ‰₯0y_i \ge 0.
    • Formula: (10+4βˆ’14βˆ’1)=(133)=13Γ—12Γ—116=286\binom{10 + 4 - 1}{4 - 1} = \binom{13}{3} = \frac{13 \times 12 \times 11}{6} = 286 ways.

🎯 Exam & Interview Pitfall Check​

Combinatorial Problem ScenarioCorrect Mathematical FormulaCommon Incorrect Trap
Distribute nn identical balls into rr distinct bins(n+rβˆ’1rβˆ’1)\binom{n + r - 1}{r - 1} (Stars and Bars)Confusing with rnr^n (which is for distinct balls)
Distribute nn distinct balls into rr distinct binsrnr^n (Rule of Product)Using (n+rβˆ’1rβˆ’1)\binom{n+r-1}{r-1}
Seating nn people in a circle(nβˆ’1)!(n - 1)!Using n!n! (forgetting rotational symmetry)
Circular gap method with mm items in circle(mβˆ’1)!Γ—mPk(m - 1)! \times {}^m P_kTreating circular gaps as (mβˆ’1)(m-1) gaps instead of mm linear gaps
Diagonals of nn-sided polygonn(nβˆ’3)2\frac{n(n - 3)}{2}Using (n2)\binom{n}{2} (forgetting to subtract nn edges)
x1+β‹―+xr=nx_1 + \dots + x_r = n with xiβ‰₯1x_i \ge 1(nβˆ’1rβˆ’1)\binom{n - 1}{r - 1}Using (n+rβˆ’1rβˆ’1)\binom{n+r-1}{r-1} without subtracting pre-allocations
Core Conceptual Questions

Question 1: What is the mathematical difference between distributing nn identical balls into rr distinct boxes versus nn distinct balls into rr distinct boxes? Key Focus Points:

  • Identical balls into distinct boxes: Stars and Bars! Formula: (n+rβˆ’1rβˆ’1)\binom{n + r - 1}{r - 1}. Only the count of balls landing in each box matters.
  • Distinct balls into distinct boxes: Rule of Product! Each unique ball independently chooses any of the rr boxes: rΓ—rΓ—β‹―Γ—r=rnr \times r \times \dots \times r = r^n.

Question 2: How many terms are in the expansion of (x1+x2+β‹―+xr)n(x_1 + x_2 + \dots + x_r)^n? Key Focus Points: Each term in the multinomial expansion has the form x1k1x2k2…xrkrx_1^{k_1} x_2^{k_2} \dots x_r^{k_r} where k1+k2+β‹―+kr=nk_1 + k_2 + \dots + k_r = n with kiβ‰₯0k_i \ge 0. The number of distinct terms is exactly the number of non-negative integer solutions to this equation:

TotalΒ Terms=(n+rβˆ’1rβˆ’1)\text{Total Terms} = \binom{n + r - 1}{r - 1}
Common Interview Traps

Trap 1: Treating Gaps in Circular Permutations as Circular Gaps Why it fails: When mm people sit in a circle, there are (mβˆ’1)!(m-1)! circular arrangements. But once they sit, each gap is uniquely bounded by two specific people (e.g., between Alice and Bob vs between Bob and Charlie). The gaps are therefore linearly distinct! The remaining kk people are arranged in mPk{}^m P_k ways, NOT (mβˆ’1)!(m-1)!.

Trap 2: Forgetting to Subtract Non-Existent Triangles from Collinear Points Why it fails: If pp points out of nn are collinear, students often write (n3)\binom{n}{3}. Any 3 points chosen from the pp collinear points form a straight line, not a triangle! You must subtract (p3)\binom{p}{3}.

πŸ’¬

Discussion & Doubts