Basic Mathematics for IT

Chapter 7
Combinatorics and Discrete Counting

Bachelors Program in IT
Basic Mathematics for IT   •   Bachelor

Combinatorics and Discrete Counting

Introduction

Combinatorics is the systematic study of finite structures and the number of ways they can be arranged, selected, or related. In information technology, counting is rarely an abstract exercise. It supports algorithm analysis, password and key-space estimation, test-case design, database query planning, network configuration, probability models, and allocation of limited resources.

A central challenge is to count each valid outcome exactly once. A result that counts some outcomes repeatedly is an overcount; one that omits valid outcomes is an undercount. This chapter develops a practical framework for avoiding both errors.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Apply the sum and product rules to finite counting problems.
  2. Use factorials, permutations, and combinations appropriately.
  3. Count arrangements with repeated objects and circular arrangements.
  4. Apply inclusion–exclusion to overlapping conditions.
  5. Use the pigeonhole principle to prove that repetition or collision must occur.
  6. Relate counting methods to algorithm analysis, probability, software testing, and resource allocation.
  7. Explain assumptions, limitations, and ethical implications of counting-based estimates.

1. Fundamental Counting Principles

1.1 What is an outcome?

An outcome is one complete result relevant to a problem. For example, a six-character password is one outcome, while a particular selection of three servers is another. The sample space is the set of all valid outcomes.

Before choosing a formula, specify:

  • what constitutes one outcome;
  • whether order matters;
  • whether repetition is allowed;
  • whether objects are distinguishable; and
  • whether restrictions exclude some outcomes.

These questions are more important than memorizing formulas.

1.2 The sum rule

If a task can be completed in one of several mutually exclusive ways, and method i has nᵢ possibilities, then the total number is

N = n₁ + n₂ + ⋯ + nk = ∑i=1k nᵢ

The methods must be mutually exclusive: no single outcome may belong to two methods. For example, a user ID may begin with a letter in 26 ways or with a digit in 10 ways, giving 36 possibilities for the first position.

If categories overlap, the sum rule alone overcounts and inclusion–exclusion is required.

1.3 The product rule

If a process consists of k successive stages and stage i has nᵢ choices for every relevant outcome of the preceding stages, then

N = n₁n₂⋯nk = ∏i=1k nᵢ

For a four-digit PIN, each position has 10 choices and repetition is allowed, so the number of PINs is 104 = 10,000. If digits cannot repeat, the count is 10 × 9 × 8 × 7 = 5,040.

The product rule also applies when the number of choices at a later stage depends on earlier choices, provided the product uses the appropriate number for each branch or the cases are partitioned correctly.

1.4 Complementary counting

Sometimes it is easier to count the total possibilities and subtract invalid ones:

|A| = |U| − |Aᶜ|

Here U is the universal set, A is the desired event, and Aᶜ is its complement. For example, among 8-bit strings, the number containing at least one 1 is 28 − 1 = 255, because only the all-zero string is excluded.

2. Factorials, Permutations, and Combinations

2.1 Factorials

For a non-negative integer n, the factorial is

n! = n(n−1)(n−2)⋯2·1, 0! = 1

The convention 0! = 1 makes formulas consistent: there is exactly one way to arrange zero objects—the empty arrangement.

2.2 Permutations of distinct objects

A permutation is an ordered arrangement. The number of arrangements of n distinct objects is

P(n,n) = n!

The number of ordered selections of r distinct objects from n objects is

P(n,r) = n(n−1)⋯(n−r+1) = n!/(n−r)!

This applies when order matters and no object is selected more than once. For example, the number of ordered three-person officer teams from 12 students is

P(12,3) = 12!/(9!) = 12 × 11 × 10 = 1,320.

2.3 Combinations

A combination is an unordered selection. The number of ways to choose r objects from n distinct objects is

C(n,r) = (n choose r) = n!/[r!(n−r)!]

The conditions are 0 ≤ r ≤ n, distinct objects, and no repetition. For a six-member project team selected from 20 applicants,

C(20,6) = 20!/(6!14!) = 38,760.

The relationship between permutations and combinations is

P(n,r) = C(n,r)r!

A combination first selects the r objects; multiplying by r! orders them.

2.4 A decision test

Ask: “Would changing the order produce a different outcome?” If yes, use a permutation or the product rule. If no, use a combination. Selecting administrators for distinct roles is ordered; selecting members of an undifferentiated committee is unordered.

2.5 Permutations with repeated objects

If n objects include groups of identical objects of sizes n₁, n₂, …, n_k, the number of distinguishable arrangements is

N = n!/(n₁!n₂!⋯nk!)

For the letters in DATA, all four letters are distinguishable, so there are 4! = 24 arrangements. For LEVEL, L and E each occur twice, so the number is 5!/(2!2!) = 30.

The division removes duplicate arrangements caused by swapping identical objects.

2.6 Circular permutations

For n distinct objects arranged around a circle, rotations are considered the same but reflections are different. Fixing one object removes rotational duplication:

N = (n−1)!

Thus, six people can be seated around a circular table in 5! = 120 rotationally distinct ways. If mirror-image arrangements are also treated as identical, an additional division by 2 is appropriate for n greater than 2, giving (n−1)!/2. The convention must be stated because different applications treat reflections differently.

3. Counting with Repetition

3.1 Ordered selections with repetition

If r positions are filled from n types and repetition is allowed, the product rule gives

N = nr

A four-symbol authentication code using 26 uppercase letters, with repetition allowed, has 264 = 456,976 possible codes.

3.2 Unordered selections with repetition

The number of ways to select r objects from n types when order does not matter and a type may be selected repeatedly is

C(n+r−1,r) = (n+r−1)!/[r!(n−1)!]

This is commonly called the stars-and-bars formula. For example, the number of non-negative integer solutions to x₁ + x₂ + ⋯ + xn = r is C(n+r−1,r).

If every type must be selected at least once, first allocate one object to each type and distribute the remaining r−n objects:

C(r−1,n−1), r ≥ n

These formulas assume identical objects within a type and distinguishable types.

4. Inclusion–Exclusion

4.1 Two sets

When sets A and B overlap, adding their sizes counts the intersection twice. Therefore,

|A ∪ B| = |A| + |B| − |A ∩ B|

For example, suppose a software repository contains 80 files using API A, 55 using API B, and 20 using both. The number using at least one API is 80 + 55 − 20 = 115.

4.2 Three or more sets

For three sets,

|A ∪ B ∪ C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|

The alternating signs correct repeated overcounting. The general form for sets A₁, …, A_k is

|⋃i=1k Ai| = ∑|Ai| − ∑|Ai∩Aj| + ∑|Ai∩Aj∩Al| − ⋯

The sums include all distinct index combinations of the indicated size.

4.3 Counting the complement

If a problem asks for outcomes satisfying none of several conditions, calculate the union of the unwanted conditions and subtract it from the universal set:

|none| = |U| − |A₁ ∪ A₂ ∪ ⋯ ∪ Ak|

In probability, the same logic applies to events. If outcomes are equally likely, P(A) = |A|/|U|. Inclusion–exclusion remains valid for probabilities, with set sizes replaced by probabilities.

5. The Pigeonhole Principle

5.1 Basic principle

If more than n objects are placed into n boxes, at least one box contains at least two objects. In formal terms, a function from a set of size n+1 to a set of size n cannot be injective.

The principle proves existence; it does not generally identify which box contains a repeated object.

Example: among 13 people, at least two were born in the same calendar month, because there are 13 people and only 12 months.

5.2 Generalized pigeonhole principle

If N objects are distributed among k boxes, at least one box contains at least

⌈N/k⌉

objects, where ⌈x⌉ is the ceiling of x. For 101 files distributed among 10 storage partitions, some partition contains at least ⌈101/10⌉ = 11 files.

To guarantee that some box contains at least r objects, it is sufficient to have

N > k(r−1), equivalently N ≥ k(r−1)+1

This is useful in collision analysis, hash tables, scheduling, and quality assurance.

5.3 Hashing interpretation

A hash function maps a potentially large key space into a finite set of hash values. If there are more possible keys than hash values, the pigeonhole principle guarantees a collision. A good hash function can distribute keys evenly, but it cannot eliminate collisions unless the mapping is injective over the actual key set.

This distinction is important: collision resistance in cryptography concerns computational difficulty, not the absence of collisions in an unlimited domain.

6. Applications in Information Technology

6.1 Algorithm analysis

Counting often estimates the size of a search space. If an algorithm examines all subsets of n items, the search space has 2n subsets. If it examines all ordered pairs of n items, the count is n2 when repetition is allowed, or n(n−1) when distinct items are required.

These counts help explain exponential, polynomial, and factorial growth. An algorithm examining all permutations has time proportional to n!, which becomes impractical rapidly. Counting is not by itself a complete time analysis: the cost per operation, data representation, pruning, and implementation also matter.

6.2 Password and authentication analysis

A code with alphabet size q and length r has qr possibilities when repetition is allowed. If an attacker can test R candidates per second, an exhaustive search requires at most q^r trials and has an average of approximately qr/2 trials under a uniform random ordering. This estimate assumes uniformly generated secrets, independent trials, no rate limiting, and no information leakage.

Human-chosen passwords often violate uniformity, so nominal key-space size can greatly overstate security. Security analysis must also consider online throttling, credential reuse, breach data, multifactor authentication, and secure password hashing.

6.3 Software testing

Suppose a system has three input fields with 5, 4, and 6 valid categories. Exhaustive category-level testing requires 5 × 4 × 6 = 120 combinations. If each field has 10 possible values, exhaustive testing requires 103 = 1,000 cases; with 20 fields it would require 1020, which is infeasible.

Test designers therefore use equivalence partitioning, boundary-value analysis, pairwise testing, covering arrays, risk-based prioritization, and combinatorial interaction testing. Pairwise testing does not guarantee that every triple or higher-order interaction is tested; its suitability depends on the failure model.

6.4 Resource allocation

If 8 tasks are assigned to 3 distinct servers and a task may be assigned to any server, there are 38 = 6,561 assignments. If each server must receive at least one task, inclusion–exclusion gives

38 − 3·28 + 3·18 = 5,796.

The subtraction removes assignments leaving one or more servers unused. Counting feasible allocations can support capacity planning, though actual optimization additionally requires costs, capacities, dependencies, and performance constraints.

7. Worked Integrated Example: API Configuration Testing

Background

This illustrative case concerns a team testing a cloud service. Each deployment selects one operating system from 3 options, one database from 4 options, and one authentication mode from 3 options. The team also wants to test selected configurations involving security features.

Problem

How many basic configurations exist? How many use a particular operating system or database? If all three security modes must appear at least once across a set of deployments, what is the smallest number of deployments that guarantees some security mode is tested at least four times?

Analysis and solution

For a single deployment, the product rule gives

3 × 4 × 3 = 36 configurations.

Suppose 18 configurations use operating system X, 15 use database D, and 8 use both. Configurations using X or D number

18 + 15 − 8 = 25.

For the final question, view the three security modes as pigeonholes. To guarantee that one mode appears at least four times, the generalized principle requires

3(4−1)+1 = 10 deployments.

With only 9 deployments, it is possible to assign exactly 3 to each mode, so four of one mode is not guaranteed.

Outcome

The team can distinguish the exhaustive configuration count (36), the overlapping requirement count (25), and the guarantee threshold (10). These are different questions and require different counting tools.

Learning points

  1. Product-rule counts describe independent successive choices.
  2. Inclusion–exclusion handles overlapping categories.
  3. The pigeonhole principle establishes guaranteed repetition.
  4. A numerical count is meaningful only when its assumptions are documented.

8. Common Errors and Best Practices

Common errors

  • Using combinations when roles or sequence make order significant.
  • Applying the product rule without checking whether choices depend on earlier choices.
  • Adding overlapping categories without subtracting intersections.
  • Treating identical objects as distinguishable.
  • Assuming a large nominal password space represents actual human password security.
  • Confusing “at least one” with “exactly one.”
  • Treating a guaranteed collision as evidence about which keys collide.

Best practices

  1. Define the outcome before calculating.
  2. State whether order and repetition matter.
  3. Partition cases so that the sum rule uses mutually exclusive categories.
  4. Use a small example or brute-force script to validate a formula.
  5. Check boundary cases such as r = 0, r = n, and empty intersections.
  6. Use logarithms or approximate growth rates when factorial or exponential counts become large.
  7. Document assumptions about independence, uniformity, capacity, and distinguishability.
  8. For security and testing, treat counting as one input to risk analysis rather than as a complete decision rule.

9. Ethical and Governance Considerations

Counting can influence security budgets, test coverage, and access decisions. Misrepresenting a key space may create false confidence; underestimating configuration combinations may leave safety-critical interactions untested. Test selection should be risk-based and should not systematically exclude vulnerable users, devices, languages, or accessibility configurations.

In privacy-sensitive systems, combinatorial linkage can make apparently harmless attributes identifying when combined. Data minimization, access controls, documented assumptions, and review of threat models are therefore essential. Automated and AI-assisted test generation can expand coverage, but generated cases require validation, traceability, and protection against exposing confidential test data.

10. Contemporary Developments

Modern software engineering increasingly uses combinatorial interaction testing, constraint solvers, symbolic execution, and property-based testing. These methods do not simply enumerate every possibility. They model constraints, generate representative cases, and search for counterexamples. Their effectiveness depends on the quality of the model and the interaction assumptions.

In distributed systems, combinatorial explosion motivates model checking with state reduction, partial-order reduction, and bounded exploration. In cybersecurity, counting supports entropy estimation and attack-cost analysis, while cryptographic security additionally requires formal threat models and computational assumptions. Thus, contemporary practice combines discrete counting with algorithms, statistics, optimization, and domain expertise.

Chapter Summary

Combinatorics provides a disciplined language for counting finite possibilities. The sum rule applies to mutually exclusive alternatives, while the product rule applies to successive choices. Factorials count complete arrangements; permutations count ordered selections; combinations count unordered selections. Repeated objects require division by factorials for indistinguishable groups, and circular arrangements require careful treatment of rotational and reflective equivalence.

Inclusion–exclusion corrects overlap among sets and extends naturally to probabilities. The pigeonhole principle proves that repetition or collision must occur when too many objects occupy too few categories. These tools are central to algorithm complexity, authentication analysis, software testing, hashing, configuration management, and resource allocation. Reliable application requires explicit assumptions about order, repetition, independence, distinguishability, and constraints. Counting is powerful, but it must be combined with risk analysis, empirical validation, and ethical governance.

Key Terms

Combinatorics: The study of finite arrangements, selections, and structures.

Outcome: One complete result relevant to a counting problem.

Sample space: The set of all valid outcomes.

Sum rule: A principle for mutually exclusive alternative cases.

Product rule: A principle for successive choices or stages.

Factorial: The product n(n−1)⋯1, with 0! defined as 1.

Permutation: An ordered arrangement or selection.

Combination: An unordered selection.

Repetition: The reuse of an object or type in an outcome.

Inclusion–exclusion: A method that corrects overcounting caused by overlaps.

Intersection: The set of outcomes common to two or more sets.

Union: The set of outcomes in at least one of several sets.

Complement: Outcomes in the universal set that are not in a specified set.

Pigeonhole principle: A result guaranteeing repetition when objects exceed boxes.

Hash collision: Two or more keys producing the same hash value.

Stars and bars: A method for unordered selections with repetition.

Exhaustive testing: Testing every outcome in a defined finite space.

Pairwise testing: Testing every combination of values for each pair of factors.

Key space: The set of possible keys, passwords, or codes.

Distinguishable object: An object treated as unique for counting purposes.

Review Questions

Short Answer Questions

  1. When should the sum rule be used, and what condition must the cases satisfy?
  2. Explain the difference between a permutation and a combination.
  3. Why is 0! = 1?
  4. State the generalized pigeonhole principle.
  5. What type of overcounting does inclusion–exclusion correct?

Long Answer Questions

  1. Derive the formula for C(n,r) from the permutation formula and explain why division by r! is necessary.
  2. Compare ordered selections with and without repetition, including an IT example of each.
  3. Explain permutations with repeated objects and apply the formula to a suitable word or identifier.
  4. Describe how exhaustive testing becomes infeasible as the number of configurable factors increases.
  5. Discuss why nominal password key-space calculations may not represent real-world security.

Analytical / Application Questions

  1. A system has 5 interface languages, 3 device classes, and 4 authentication methods. Calculate the number of configurations, then determine how many remain if one language and one authentication method are prohibited.
  2. A database contains 120 records in set A, 90 in set B, and 35 in both. Calculate the number in at least one set and explain the counting assumption.
  3. A scheduler assigns 25 jobs to 6 servers. Use the generalized pigeonhole principle to determine the minimum number of jobs guaranteed on some server, and determine how many jobs guarantee at least 5 on one server.

Multiple Choice Questions with Answers

Question 1

A six-character code uses 10 digits, with repetition allowed. How many codes are possible?

A. 60

B. 600

C. 1,000,000

D. 3,628,800

Correct Answer: C. 1,000,000

Question 2

Which expression counts the number of unordered committees of 4 selected from 10 distinct people?

A. 10⁴

B. 10!/6!

C. 10!/(4!6!)

D. 4!/(10!6!)

Correct Answer: C. 10!/(4!6!)

Question 3

How many ordered selections of 3 distinct servers can be made from 8 servers?

A. 24

B. 56

C. 336

D. 512

Correct Answer: C. 336

Question 4

If |A| = 40, |B| = 25, and |A ∩ B| = 9, what is |A ∪ B|?

A. 56

B. 65

C. 74

D. 90

Correct Answer: A. 56

Question 5

How many distinguishable arrangements can be made from the letters in LEVEL?

A. 20

B. 30

C. 60

D. 120

Correct Answer: B. 30

Question 6

What is the number of subsets of a set containing 7 elements?

A. 14

B. 49

C. 128

D. 5040

Correct Answer: C. 128

Question 7

At least how many objects are needed in 5 boxes to guarantee that one box contains at least 4 objects?

A. 9

B. 15

C. 16

D. 20

Correct Answer: C. 16

Question 8

Which condition is required for direct use of the sum rule?

A. All cases overlap

B. Cases are mutually exclusive

C. Order must matter

D. Repetition must be prohibited

Correct Answer: B. Cases are mutually exclusive

Question 9

How many ways can 4 distinct people be arranged around a circle when rotations are considered identical and reflections distinct?

A. 4

B. 6

C. 12

D. 24

Correct Answer: B. 6

Question 10

A test has 3 independent factors with 4, 5, and 2 categories. How many category-level combinations exist?

A. 11

B. 20

C. 40

D. 120

Correct Answer: C. 40

Basic Mathematics for IT
Chapter 7 of 15