Course contentsShow
← Computer Science
Lesson 98 of 2,8722. Discrete Mathematics for CSFree lesson

Counting Principles: Sum and Product Rules

Learn the fundamental addition and multiplication principles for counting distinct outcomes in combinatorial problems.

Counting Principles: Sum and Product Rules

You'll learn how to count possible outcomes when making choices using two fundamental rules.

The Core Idea

When solving problems that ask "how many ways can something happen?", you need systematic counting methods. Two foundational principles help:

The Sum Rule (Addition Principle): If you can do task A in m ways OR task B in n ways, and these tasks cannot happen simultaneously, then there are m + n total ways to do either task.

The Product Rule (Multiplication Principle): If you must do task A in m ways AND then task B in n ways, there are m × n total ways to complete both tasks in sequence.

Understanding Through Examples

Sum Rule (OR situations)

Imagine choosing a programming language to learn. If you can pick from 3 backend languages (Python, Java, Go) OR 2 frontend languages (JavaScript, TypeScript), you have 3 + 2 = 5 total choices. You pick one language, not both types.

Product Rule (AND situations)

Suppose you're creating a username. You must choose a letter (26 options) AND then a digit (10 options). By the product rule, there are 26 × 10 = 260 possible usernames. Each choice affects the final outcome.

When to Use Which

  • Sum Rule: Mutually exclusive options (this OR that)
  • Product Rule: Sequential decisions (this AND then that)

These rules extend to multiple tasks: choosing from 3 databases OR 4 cache systems gives 3 + 4 = 7 options; creating a password with 3 letters AND 2 digits gives 26 × 26 × 26 × 10 × 10 = 1,757,600 combinations.

Key Takeaway: Use the sum rule when counting separate alternatives (OR), and the product rule when counting sequential choices (AND).