Discrete Mathematics – Complete Study Notes

Logic • Proofs • Set Theory • Abstract Algebra • Advanced Counting

Unit 1 – Logic and its Applications

Foundation of mathematical reasoning and digital circuits.

1.1 Propositional Logic

A proposition is a declarative statement that is either true (T) or false (F)—never both. Propositional logic studies how propositions combine to form compound statements.

Definition – Proposition

A statement with a definite truth value. Examples:
✔ "2 + 2 = 4" (T)    ✔ "Paris is in Germany" (F)
✘ "What time is it?" (question — not a proposition)
✘ "x > 5" (open sentence, truth depends on x)

Logical Connectives

SymbolNameMeaningTrue when …
¬pNegation (NOT)not pp is F
p ∧ qConjunction (AND)p and qboth T
p ∨ qDisjunction (OR)p or qat least one T
p → qImplicationif p then qp is F, or both T
p ↔ qBiconditionalp if and only if qsame truth value
p ⊕ qXOR (Exclusive OR)p exclusive or qexactly one T

Truth Table for Implication (→)

The implication p → q is false only when p is true and q is false. In all other cases it is true. Think of it as a promise: the promise is only broken when you do the condition but not the result.

pqp→q¬p∨q (equivalent form)
TTTT
TFFF
FTTT
FFTT

Key Terminology

Tautology, Contradiction, Contingency

Important Logical Equivalences

LawEquivalence
Double Negation¬(¬p) ≡ p
De Morgan's (AND)¬(p ∧ q) ≡ ¬p ∨ ¬q
De Morgan's (OR)¬(p ∨ q) ≡ ¬p ∧ ¬q
Implication Rewritep → q ≡ ¬p ∨ q
Contrapositivep → q ≡ ¬q → ¬p
Absorptionp ∨ (p ∧ q) ≡ p
Distributivep ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)

1.1a Logical Equivalences of Conditional & Biconditional Statements

Equivalences of p → q (Conditional / Implication)

The conditional p → q has several important equivalent and non-equivalent forms. Knowing which are equivalent and which are not is a key B.Tech exam skill.

All Key Equivalences for p → q
FormExpressionEquivalent to p→q?Explanation
Originalp → qBase implication
Contrapositive¬q → ¬pYES ✓Flip and negate both — always equivalent
Converseq → pNO ✗Just flip — NOT equivalent
Inverse¬p → ¬qNO ✗Just negate both — NOT equivalent (≡ converse)
OR form¬p ∨ qYES ✓Standard rewrite
NAND form¬(p ∧ ¬q)YES ✓Negation of "p and not q"
Exportation(p ∧ q) → r ≡ p → (q → r)YES ✓Used in proofs to "export" a premise
B.Tech Exam Tip

Equivalence pairs to memorise:

Truth Table — Comparing All Four Forms
pqp→q (original)q→p (converse)¬p→¬q (inverse)¬q→¬p (contrapositive)
TTTTTT
TFFTTF
FTTFFT
FFTTTT

Columns 3 and 6 are identical → p→q ≡ contrapositive ✓
Columns 4 and 5 are identical → converse ≡ inverse ✓ (but both differ from column 3)

Equivalences of p ↔ q (Biconditional)

The biconditional p ↔ q ("p if and only if q") is true exactly when p and q have the same truth value. It has several useful equivalent forms.

Key Equivalences for p ↔ q
Equivalent FormExpressionWhy
Both-implications(p→q) ∧ (q→p)Definition: "if and only if" = both directions hold
Same-value cases(p∧q) ∨ (¬p∧¬q)True when both T or both F
Double OR form(¬p∨q) ∧ (¬q∨p)Expand each implication as ¬p∨q
Negated complement¬p ↔ ¬qNegating both sides preserves biconditional
Negation (XOR)¬(p↔q) ≡ p⊕qTrue when p and q differ — exclusive OR
Truth Table Verification — p↔q ≡ (p∧q)∨(¬p∧¬q)
pqp↔qp∧q¬p∧¬q(p∧q)∨(¬p∧¬q)
TTTTFT
TFFFFF
FTFFFF
FFTFTT

Columns 3 and 6 match ✓

Practice Questions – Conditional & Biconditional Equivalences
Q1. For the statement "If you study hard, you will pass", write the (a) converse (b) inverse (c) contrapositive. Which are equivalent?

Let p = "you study hard", q = "you will pass".

(a) Converse: q→p = "If you pass, you studied hard." (NOT equivalent)

(b) Inverse: ¬p→¬q = "If you do not study hard, you will not pass." (NOT equivalent; ≡ converse)

(c) Contrapositive: ¬q→¬p = "If you do not pass, you did not study hard." (EQUIVALENT to original)

Q2. Show that p↔q ≡ (p→q) ∧ (q→p) using a truth table.
pqp↔qp→qq→p(p→q)∧(q→p)
TTTTTT
TFFFTF
FTFTFF
FFTTTT

Columns 3 and 6 are identical. ✓ Proved.

Q3. Is the converse of a true conditional always true? Give an example.

No. A true conditional does NOT guarantee a true converse.

Example: p→q = "If a number is divisible by 4, it is divisible by 2." TRUE.

Converse q→p = "If a number is divisible by 2, it is divisible by 4." FALSE (e.g., 6 is divisible by 2 but not 4).

Q4. Rewrite p→q using only ∧ and ¬ (no ∨ or →).

p→q ≡ ¬p∨q  [standard rewrite]

¬p∨q ≡ ¬(p∧¬q)  [De Morgan's: ¬(A∧B) = ¬A∨¬B, reversed]

Answer: p→q ≡ ¬(p ∧ ¬q)

1.1b Satisfiability and the Sudoku Puzzle

Satisfiability

Definition – Satisfiability

A propositional formula φ is:

Quick check: φ is unsatisfiable ↔ ¬φ is a tautology.

SAT Problem — NP-Complete

The Boolean Satisfiability Problem (SAT): given a propositional formula in CNF, decide if it is satisfiable.

Examples – Classifying Formulas
FormulaSatisfiable?Tautology?Reason
p ∨ ¬pYesYesAlways true (excluded middle)
p ∧ ¬pNoNoAlways false (contradiction)
p ∧ qYes (p=T,q=T)NoTrue for one assignment only
(p→q) ∧ p ∧ ¬qNoNop,¬q makes p→q false; contradiction

Sudoku as a Satisfiability Problem

Sudoku Puzzle — Visual Diagram

A standard 9×9 Sudoku. Each row, column, and bold 3×3 box must contain digits 1–9 exactly once. Pre-filled cells are the given clues.

53· ·7· ···
6·· 195 ···
·98 ··· ·6·
8·· ·6· ··3
4·· 8·3 ··1
7·· ·2· ··6
·6· ··· 28·
··· 419 ··5
··· ·8· ·79

SAT Encoding

Each cell (i,j) and digit k is a Boolean variable:

p(i,j,k) = 1 if cell (i,j) holds digit k

Example: the blue cell at row 1, col 1 (value=5) gives the unit clause:
p(1,1,5) = TRUE

Total: 9×9×9 = 729 variables

Constraints as clauses:
At-least-one per cell, at-most-one per cell, row/col/box uniqueness = thousands of clauses

A SAT solver finds a satisfying assignment = the completed puzzle.

Encoding Sudoku as SAT

Every Sudoku puzzle can be converted into a SAT problem and solved by a SAT solver. This shows how logic is applied in practice.

Variables: p(i, j, k) = "cell in row i, column j contains digit k"  (i,j,k ∈ {1,…,9})

Total variables: 9 × 9 × 9 = 729 Boolean variables

Constraints (encoded as clauses):

A SAT solver (e.g., MiniSAT) finds a satisfying assignment → the solution to the puzzle, in milliseconds.

Practice Questions – Satisfiability
Q1. Is (p ∨ q) ∧ (¬p ∨ r) ∧ (¬q ∨ ¬r) satisfiable?

Try p=T, q=F, r=T:

(T∨F) ∧ (F∨T) ∧ (T∨F) = T ∧ T ∧ T = T ✓

Yes, satisfiable. Assignment: p=T, q=F, r=T satisfies all three clauses.

Q2. Is (p ∨ q) ∧ ¬p ∧ ¬q satisfiable?

From ¬p and ¬q: p=F, q=F.

Then p∨q = F∨F = F. So (p∨q)∧¬p∧¬q = F.

No other assignments are possible since ¬p and ¬q force p=F, q=F.

No, unsatisfiable (contradiction).

Q3. How many truth assignments satisfy p ↔ q when there are 2 variables?

p↔q is true when p and q have the same value.

Satisfying assignments: (T,T) and (F,F) — exactly 2 out of 4.

Answer: 2 satisfying assignments.

Worked Example – Show p→q ≡ ¬p∨q

Build a truth table and verify column p→q equals column ¬p∨q:

pq¬pp→q¬p∨q
TTFTT
TFFFF
FTTTT
FFTTT

Columns 4 and 5 are identical → equivalence confirmed ✓

Practice Questions – Propositional Logic
Q1. Is (p ∨ q) ∧ ¬p → q a tautology?

Solution: We need: whenever (p∨q)∧¬p is T, q must also be T.

(p∨q)∧¬p is T only when p=F and q=T (¬p=T requires p=F; p∨q=T requires q=T when p=F).

In that case q=T, so the implication holds. In all other cases the hypothesis is F → implication is automatically T.

Yes, it is a tautology (this is Disjunctive Syllogism).

Q2. Write the contrapositive of: "If it rains, then the ground is wet."

Let p = "It rains", q = "The ground is wet". Original: p → q.

Contrapositive: ¬q → ¬p.

Answer: "If the ground is not wet, then it did not rain."

The contrapositive is logically equivalent to the original.

Q3. Simplify ¬(p → q).

p → q ≡ ¬p ∨ q

¬(p → q) ≡ ¬(¬p ∨ q) ≡ p ∧ ¬q  [De Morgan's]

Answer: p ∧ ¬q (p is true AND q is false — the only case when an implication fails).

Q4. Is (p ∧ q) → p always true?

If p∧q is T → both p and q are T → p is T → implication is T.

If p∧q is F → false antecedent → implication is T.

Yes, it is a tautology (Simplification rule of inference).

1.2 Predicate Logic & Quantifiers

Propositional logic cannot express statements like "All students passed." Predicate logic adds predicates (properties) and quantifiers (all, some) to express such statements.

Definition – Predicate

A predicate P(x) is a statement containing a variable x. It becomes a proposition when x is assigned a specific value.

Example: P(x) = "x > 5". P(10) is T, P(3) is F.

Universal and Existential Quantifiers

QuantifierSymbolMeaningFalse when …
Universal∀x P(x)"For all x, P(x)"At least one x makes P(x) false
Existential∃x P(x)"There exists x such that P(x)"No x makes P(x) true

Negation of Quantifiers (De Morgan's for Quantifiers)

Theorem

¬(∀x P(x)) ≡ ∃x ¬P(x)

¬(∃x P(x)) ≡ ∀x ¬P(x)

Intuition: "Not all students passed" ≡ "Some student did not pass."

Nested Quantifiers — Order Matters!

StatementMeaning
∀x ∃y P(x,y)For every x, there is some y that works (y may depend on x)
∃y ∀x P(x,y)One single y works for all x (much stronger!)
Example – Nested Quantifiers

Domain: real numbers. P(x,y) = "x + y = 0"

∀x ∃y P(x,y) → TRUE (for any x, choose y = −x)

∃y ∀x P(x,y) → FALSE (no single y satisfies x + y = 0 for all x)

Practice Questions – Predicate Logic
Q1. Negate: "Every student has a laptop."

Let L(x) = "x has a laptop", domain = students.

Original: ∀x L(x). Negation: ¬(∀x L(x)) ≡ ∃x ¬L(x).

Answer: "There exists a student who does not have a laptop."

Q2. Express "Some birds cannot fly" using predicates.

Let B(x) = "x is a bird", F(x) = "x can fly".

Answer: ∃x (B(x) ∧ ¬F(x))

Important: Use ∧ (not →) with ∃. Writing ∃x (B(x) → ¬F(x)) would be true even if there are no birds, which is wrong!

Q3. Negate: ∀x ∀y (x ≠ y → P(x,y))

¬(∀x ∀y (x≠y → P(x,y)))

≡ ∃x ∃y ¬(x≠y → P(x,y))

≡ ∃x ∃y (x≠y ∧ ¬P(x,y))  [since ¬(A→B) ≡ A∧¬B]

Answer: "There exist two distinct elements for which P(x,y) does not hold."

1.3 Boolean Algebra & Computer Architecture Applications

Boolean Algebra is the mathematical foundation of digital circuits. Variables take values 0 (false) or 1 (true). The three basic operations are AND (·), OR (+), NOT (').

Boolean Laws

LawAND formOR form
IdentityA · 1 = AA + 0 = A
Null/DominationA · 0 = 0A + 1 = 1
IdempotentA · A = AA + A = A
ComplementA · A' = 0A + A' = 1
De Morgan's(A·B)' = A'+B'(A+B)' = A'·B'
AbsorptionA·(A+B) = AA + A·B = A

Logic Gates

Logic gates are the physical building blocks of digital circuits. Each gate implements a Boolean operation. Below are the standard IEEE symbols, truth tables, and key properties.

GateOperationOutput 1 when …Universal Gate?
ANDA · BAll inputs are 1No
ORA + BAt least one input is 1No
NOTA'Input is 0No
NAND(A·B)'Not all inputs are 1Yes
NOR(A+B)'All inputs are 0Yes
XORA ⊕ BExactly one input is 1No
Logic Gate Diagrams (Standard IEEE Symbols)
AND Gate
A B Y
Y = A · B
ABY
000
010
100
111
OR Gate
A B Y
Y = A + B
ABY
000
011
101
111
NOT Gate (Inverter)
A Y
Y = A'
AY
01
10
NAND Gate ★ Universal
A B Y
Y = (A · B)'
ABY
001
011
101
110
NOR Gate ★ Universal
A B Y
Y = (A + B)'
ABY
001
010
100
110
XOR Gate
A B Y
Y = A ⊕ B
ABY
000
011
101
110
Universal Gates — Why NAND and NOR?

NAND and NOR are called universal gates because ANY Boolean function (AND, OR, NOT, XOR, …) can be built using only NAND gates (or only NOR gates). This is important in chip manufacturing — you only need one type of gate to build an entire CPU.

NOT using NAND:  A' = NAND(A, A)
AND using NAND:  A·B = NAND(NAND(A,B), NAND(A,B))
OR using NAND:   A+B = NAND(NAND(A,A), NAND(B,B))

1.3a Boolean Functions, Literals, Minterms, Maxterms, DNF & CNF

Boolean Function

Definition – Boolean Function

A Boolean function of n variables is a mapping f : {0,1}ⁿ → {0,1}.

n (variables)Input combinations (2ⁿ)Distinct functions (2^(2ⁿ))
124
2416
38256

Literal

Definition – Literal

A literal is a variable or the complement of a variable.

For variable x: literals are x (positive literal) and x' or ¬x (negative literal).

Example: In expression AB' + A'C, the literals are A, B', A', C.

Elementary Product & Elementary Sum

Definitions

Elementary Product (Fundamental Product): AND of one or more literals, where no variable appears more than once.

Examples: A, AB', A'BC, x'yz

Elementary Sum (Fundamental Sum): OR of one or more literals, where no variable appears more than once.

Examples: A, A+B', A'+B+C'

Minterm

Definition – Minterm

A minterm of n variables is an elementary product in which every variable appears exactly once (either complemented or not).

Minterms for 2 variables (A, B):

Row iABMinterm mᵢExpression
000m₀A'B'
101m₁A'B
210m₂AB'
311m₃AB

Rule: For minterm mᵢ, write each variable complemented if its bit in i is 0, and uncomplemented if the bit is 1.

Maxterm

Definition – Maxterm

A maxterm of n variables is an elementary sum in which every variable appears exactly once.

Maxterms for 2 variables:

Row iABMaxterm MᵢExpression
000M₀A+B
101M₁A+B'
210M₂A'+B
311M₃A'+B'

Rule: For maxterm Mᵢ, write each variable uncomplemented if its bit in i is 0, and complemented if the bit is 1 — opposite of minterm.

Disjunctive Normal Form (DNF) — Sum of Products (SOP)

Definition – DNF / Canonical SOP

DNF (Canonical DNF) = OR of all minterms for which the function outputs 1.

Written: f = Σm(list of row indices where f=1)

Steps to find DNF from a truth table:

  1. Write out the truth table for f
  2. Identify every row where f = 1
  3. Write the minterm for each such row
  4. OR all those minterms together

Every Boolean function has a unique canonical DNF.

Conjunctive Normal Form (CNF) — Product of Sums (POS)

Definition – CNF / Canonical POS

CNF (Canonical CNF) = AND of all maxterms for which the function outputs 0.

Written: f = ΠM(list of row indices where f=0)

Steps to find CNF:

  1. Write out the truth table for f
  2. Identify every row where f = 0
  3. Write the maxterm for each such row
  4. AND all those maxterms together

Every Boolean function has a unique canonical CNF.

Worked Example – Find DNF and CNF for f(A,B) = A ∨ B
RowABf=A+BMintermMaxterm
0000m₀=A'B'M₀=A+B
1011m₁=A'BM₁=A+B'
2101m₂=AB'M₂=A'+B
3111m₃=ABM₃=A'+B'

DNF: f = Σm(1,2,3) = A'B + AB' + AB

CNF: f = ΠM(0) = (A+B)

Both simplify to A+B — consistent! ✓

Practice Questions – DNF, CNF, Minterms, Maxterms
Q1. Find the canonical DNF and CNF for f(A,B) where f=1 only when A=1,B=0.
ABf
000
010
101
110

DNF: f = 1 only at row 2 (A=1,B=0). Minterm m₂ = AB'.

f = Σm(2) = AB'

CNF: f = 0 at rows 0,1,3. Maxterms: M₀=A+B, M₁=A+B', M₃=A'+B'.

f = ΠM(0,1,3) = (A+B)(A+B')(A'+B')

Q2. Express f(A,B,C) = Σm(1,4,5,7) as a product of maxterms (CNF).

DNF uses minterms at rows 1,4,5,7. So CNF uses maxterms at ALL OTHER rows: 0,2,3,6.

Rows where f=0: 0,2,3,6.

Maxterms (3 variables A,B,C):

M₀ = A+B+C (row 000)

M₂ = A+B'+C (row 010)

M₃ = A+B'+C' (row 011)

M₆ = A'+B+C' (row 110)

f = ΠM(0,2,3,6) = (A+B+C)(A+B'+C)(A+B'+C')(A'+B+C')

Q3. How many minterms and maxterms exist for a 3-variable Boolean function?

For n=3 variables (A,B,C): 2³ = 8 minterms (m₀ to m₇) and 8 maxterms (M₀ to M₇).

And there are 2^8 = 256 possible distinct Boolean functions of 3 variables.

1.3b Karnaugh Map (K-map)

A Karnaugh Map (K-map) is a graphical method to simplify Boolean expressions without algebraic manipulation. It works by visually grouping adjacent minterms whose combined expression simplifies.

Key Rules for K-map Simplification

K-map Layout for 2 Variables

2-Variable K-map
        B=0    B=1
A=0  [  m₀  |  m₁  ]
A=1  [  m₂  |  m₃  ]
  

Adjacent cells (differ by 1 bit): m₀↔m₁, m₀↔m₂, m₁↔m₃, m₂↔m₃, and wrap-around edges.

K-map for 3 Variables

3-Variable K-map Layout (2 rows × 4 columns)

One variable on rows (A), two variables on columns (BC) in Gray code order: 00, 01, 11, 10

         BC=00  BC=01  BC=11  BC=10
  A=0  [  m₀  |  m₁  |  m₃  |  m₂  ]
  A=1  [  m₄  |  m₅  |  m₇  |  m₆  ]
  

Note: The columns are NOT in binary order — they use Gray code (00,01,11,10) so adjacent columns always differ by 1 bit. This is essential for the method to work correctly.

Worked Example – Simplify f(A,B,C) = Σm(0,1,3,7) using 3-variable K-map

Step 1: Fill in the K-map

         BC=00  BC=01  BC=11  BC=10
  A=0  [  1   |  1   |  1   |  0   ]   ← m₀=1, m₁=1, m₃=1, m₂=0
  A=1  [  0   |  0   |  1   |  0   ]   ← m₄=0, m₅=0, m₇=1, m₆=0
  

Step 2: Identify groups of 1s

Step 3: OR all groups together

f = A'B' + A'C + BC

Compare to the raw DNF: m₀+m₁+m₃+m₇ = A'B'C' + A'B'C + A'BC + ABC — much longer! K-map gives the minimal form. ✓

Example – Group Sizes and What They Eliminate
Group SizeVariables EliminatedVariables Remaining in Term
1 (single cell)0All n (full minterm)
2 cells1n−1
4 cells2n−2
8 cells (all in 3-var map)30 → f = 1 (tautology)
Practice Questions – K-map
Q1. Use a 3-variable K-map to simplify f(A,B,C) = Σm(0,2,4,6).

Fill K-map:

         BC=00  BC=01  BC=11  BC=10
  A=0  [  1   |  0   |  0   |  1   ]   m₀=1, m₁=0, m₃=0, m₂=1
  A=1  [  1   |  0   |  0   |  1   ]   m₄=1, m₅=0, m₇=0, m₆=1
      

Group all four 1s: m₀,m₂,m₄,m₆ — these are BC=00 and BC=10 columns, both rows.

In these cells: A varies (0,1), B varies (0,1), C = 0 always.

The common factor: C' (C=0)

f = C' — the function is simply 1 whenever C=0.

Q2. Simplify f(A,B,C) = Σm(1,3,5,7) using K-map.
         BC=00  BC=01  BC=11  BC=10
  A=0  [  0   |  1   |  1   |  0   ]   m₁=1, m₃=1
  A=1  [  0   |  1   |  1   |  0   ]   m₅=1, m₇=1
      

Group all four 1s: m₁,m₃,m₅,m₇ — BC=01 and BC=11 columns, both rows.

In all these cells: C=1 always. A and B vary.

f = C — true whenever C=1.

Q3. Find the simplified DNF for f(A,B,C) = Σm(0,1,2,3,6).
         BC=00  BC=01  BC=11  BC=10
  A=0  [  1   |  1   |  1   |  1   ]   m₀,m₁,m₃,m₂ = all 1
  A=1  [  1   |  0   |  0   |  1   ]   m₄=1, m₅=0, m₇=0, m₆=1
      

Group 1 (size 4): Entire A=0 row → m₀,m₁,m₂,m₃ → A=0 → term: A'

Group 2 (size 2): m₀,m₄ (BC=00 column) → B=0,C=0 → term: B'C'

Group 3 (size 2): m₂,m₆ (BC=10 column) → B=1,C=0 → term: BC'

Note: m₀ is covered by both Group 1 and 2 (allowed). m₂ covered by both Group 1 and 3.

f = A' + B'C' + BC'

This can further simplify: B'C' + BC' = C'(B'+B) = C'. So f = A' + C'.

Q4. Why must K-map groups have sizes that are powers of 2?

Because we need to eliminate exactly one variable per doubling. Each time a group doubles in size, one variable changes across the group (0→1 or 1→0), so it can be eliminated from the simplified term.

For example: a group of 2 cells → 1 variable eliminated. Group of 4 → 2 variables eliminated. Group of 3 cells would not correspond to any clean Boolean simplification.

Example – Simplify Boolean Expression

Simplify: F = AB' + AB + A'B

  1. Group first two terms: AB' + AB = A(B' + B) = A · 1 = A
  2. Expression becomes: A + A'B
  3. Apply consensus theorem: A + A'B = A + B

Result: F = A + B

Practice Questions – Boolean Algebra
Q1. Simplify F = A + A'B using Boolean laws.

F = A + A'B

= (A + A')(A + B)  [Distributive: x + yz = (x+y)(x+z)]

= 1 · (A + B) = A + B

Answer: F = A + B

Q2. Implement XOR using only NAND gates.

Circuit (4 NAND gates):

G1 = NAND(A, B)

G2 = NAND(A, G1)

G3 = NAND(B, G1)

Output = NAND(G2, G3)

Proof: NAND(G2,G3) = (G2·G3)' = ((A·G1)'·(B·G1)')' = A⊕B ✓

Q3. Prove De Morgan's law ¬(A ∧ B) = ¬A ∨ ¬B using truth table.
ABA∧B¬(A∧B)¬A¬B¬A∨¬B
0001111
0101101
1001011
1110000

Columns 4 and 7 are identical. ✓ Proved.

Unit 2 – Proofs

Formal methods for establishing mathematical truth.

2.1 Definitions & Axiomatic Systems

Key Terminology
Axiomatic System – Peano Axioms for Natural Numbers
  1. 0 is a natural number.
  2. For every natural number n, S(n) (its successor) is a natural number.
  3. 0 is not the successor of any natural number.
  4. If S(m) = S(n) then m = n (successors are injective).
  5. Induction Axiom: If P(0) is true and [P(n) → P(S(n))] for all n, then P(n) is true for all natural numbers n.

2.2 Rules of Inference

Rules of inference are valid argument forms. If the premises are true, the conclusion must be true. They are the "legal moves" in a proof.

Rule NamePremisesConclusionExample
Modus Ponens (MP)p, p→qq"If it rains, ground is wet. It rains. ∴ Ground is wet."
Modus Tollens (MT)¬q, p→q¬p"Ground not wet. If rain, ground wet. ∴ No rain."
Hypothetical Syllogismp→q, q→rp→rChain of implications.
Disjunctive Syllogismp∨q, ¬pq"Heads or tails. Not heads. ∴ Tails."
Additionpp∨q"It rains. ∴ It rains or snows."
Simplificationp∧qp"It rains and is cold. ∴ It rains."
Conjunctionp, qp∧qCombining two true facts.
Resolutionp∨q, ¬p∨rq∨rUsed in automated theorem proving.
Example – Chain Reasoning

Given: (1) p→q   (2) q→r   (3) p.  Prove: r.

  1. From (1) and (2) by Hypothetical Syllogism: p→r
  2. From p→r and (3) p by Modus Ponens: r ✓
Practice Questions – Rules of Inference
Q1. Identify the fallacy: "If it rains, the match is cancelled. The match was cancelled. Therefore it rained."

This is the Fallacy of Affirming the Consequent.

Invalid form: p→q, q ⊬ p.

The match could have been cancelled for other reasons (pitch damage, no players, etc.).

Contrast with valid Modus Ponens (p→q, p ∴ q) — affirm the antecedent, not consequent.

Q2. "It is hot or sunny. It is not hot." Conclude what you can.

Premises: H ∨ S, ¬H.

By Disjunctive Syllogism: From H∨S and ¬H → conclude S.

Answer: It is sunny.

2.3 Types of Proofs

1. Direct Proof

Assume the hypothesis is true, then use logical steps to derive the conclusion directly.

Example – If n is even, then n² is even

Assume n is even → n = 2k for some integer k.

Then n² = (2k)² = 4k² = 2(2k²). Since 2k² is an integer, n² is even. ∎

2. Proof by Contrapositive

Instead of proving p→q, prove the logically equivalent ¬q→¬p.

Example – If n² is odd, then n is odd

Contrapositive: "If n is even, then n² is even" — proved above! ∎

3. Proof by Contradiction

Assume the statement is false; derive a logical contradiction, proving the statement must be true.

Classic Example – √2 is Irrational
  1. Assume √2 is rational: √2 = p/q where p,q are integers with gcd(p,q)=1 (fully reduced).
  2. Then 2 = p²/q², so p² = 2q² → p² is even → p is even → p = 2k for some k.
  3. Substitute: (2k)² = 2q² → 4k² = 2q² → q² = 2k² → q² is even → q is even.
  4. Both p and q are even, contradicting gcd(p,q) = 1. ✗
  5. ∴ Our assumption was wrong. √2 is irrational. ∎

4. Mathematical Induction

Used to prove statements about all natural numbers. Works like an infinite chain of dominoes.

Structure of a Proof by Induction

Base Case: Prove P(n₀) is true (usually n₀ = 0 or 1).

Inductive Step: Assume P(k) is true (Inductive Hypothesis, IH). Using this assumption, prove P(k+1) is true.

Conclusion: P(n) is true for all n ≥ n₀.

Example – Sum Formula

Prove: \(1 + 2 + \cdots + n = \dfrac{n(n+1)}{2}\)

  1. Base case n=1: LHS = 1, RHS = 1·2/2 = 1. ✓
  2. IH: Assume \(1+2+\cdots+k = \dfrac{k(k+1)}{2}\) for some k ≥ 1.
  3. Prove for k+1: \(1+\cdots+k+(k+1) = \dfrac{k(k+1)}{2} + (k+1) = (k+1)\left(\dfrac{k}{2}+1\right) = \dfrac{(k+1)(k+2)}{2}\) ✓

This matches the formula with n = k+1. ∎

5. Proof by Cases

Divide all possibilities into a finite number of cases and prove the statement for each case.

Example – n² + n is always even

Case 1: n is even. n = 2k → n² + n = 4k² + 2k = 2(2k²+k). Even. ✓

Case 2: n is odd. n = 2k+1 → n² + n = (2k+1)² + (2k+1) = 4k²+4k+1+2k+1 = 4k²+6k+2 = 2(2k²+3k+1). Even. ✓

Both cases give even → n² + n is always even. ∎

Practice Questions – Types of Proofs
Q1. Prove: The sum of two odd integers is even. (Direct Proof)

Let a = 2m+1 and b = 2n+1 be two odd integers.

a + b = (2m+1) + (2n+1) = 2m + 2n + 2 = 2(m+n+1).

Since m+n+1 is an integer, a+b is even. ∎

Q2. Prove by induction: \(1^2 + 2^2 + \cdots + n^2 = \frac{n(n+1)(2n+1)}{6}\)

Base case n=1: LHS=1, RHS=1·2·3/6=1. ✓

IH: Assume true for k.

Prove for k+1:

\(\frac{k(k+1)(2k+1)}{6} + (k+1)^2 = (k+1)\left[\frac{k(2k+1)}{6} + (k+1)\right]\)

\(= (k+1) \cdot \frac{k(2k+1) + 6(k+1)}{6} = (k+1) \cdot \frac{2k^2+7k+6}{6} = \frac{(k+1)(k+2)(2k+3)}{6}\) ✓ ∎

Q3. Prove there are infinitely many primes. (Contradiction)

Assume finitely many primes: p₁, p₂, …, pₙ.

Let N = p₁·p₂·⋯·pₙ + 1.

N is not divisible by any pᵢ (remainder 1 each time).

So N is either prime (a new prime!) or has a prime factor not in our list. Either way, contradicts our assumption. ∎

2.4 Program Correctness & Loop Invariants

Hoare Triple: {P} S {Q}

If precondition P is true before executing statement S, and S terminates, then postcondition Q is true afterward.

Example: {x = 5} x = x + 1 {x = 6}

Loop Invariant

A condition that is true before the loop starts, remains true after each iteration, and after termination implies the desired result.

Three proof obligations:

Example – Loop Invariant for Computing n!
result = 1; i = 1;
while (i <= n):
    result = result * i
    i = i + 1

Invariant: At the start of each iteration, result = (i−1)!

Initialization: Before loop: i=1, result=1 = (1−1)! = 0! = 1. ✓

Maintenance: If result=(i−1)! at start, after body: result = (i−1)!·i = i!, and i increments, so new (i−1)! refers to what's now i!. ✓

Termination: Loop exits when i=n+1. Invariant gives result = (n+1−1)! = n!. ✓

Practice Question
Q1. State and verify a loop invariant for binary search.
low=0; high=n-1
while (low <= high):
    mid = (low+high)/2
    if A[mid]==target: return mid
    elif A[mid] < target: low = mid+1
    else: high = mid-1
return -1

Invariant: If target exists in A, it lies within A[low..high].

Init: Before loop, A[low..high] = entire array. Invariant trivially holds. ✓

Maintenance: If A[mid] < target, target must be in right half → set low=mid+1 preserves invariant. Similarly for the other branch. ✓

Termination: low > high means search space is empty → target not present → return −1 is correct. ✓

Unit 3 – Set Theory

Foundations of mathematics and computability theory.

3.1 Russell's Paradox

The Paradox (Bertrand Russell, 1901)

In naive set theory, any property defines a set. Define:

\[ R = \{ S \mid S \notin S \} \quad \text{(the set of all sets that do NOT contain themselves)} \]

The question: Does R contain itself?

Both cases lead to contradiction → naive set theory is inconsistent!

The Barber Paradox (Informal Illustration)

In a village, the barber shaves every man who does not shave himself, and only those men. Who shaves the barber?

Conclusion: Such a barber cannot exist — and similarly, the "set of all sets" cannot exist.

Resolution: ZFC Axiomatic Set Theory

Zermelo-Fraenkel Set Theory (ZFC)

ZFC restricts set formation to avoid the paradox:

Practice Questions
Q1. Why can't we just define a "set of all sets" in mathematics?

If U = set of all sets exists, then R = {S ∈ U : S ∉ S} would be a valid set by the Separation Axiom.

But then R ∈ R ↔ R ∉ R — Russell's paradox again.

Therefore, a "set of all sets" cannot exist consistently. Instead, we use a "proper class" (collection too large to be a set) which is not itself a set and cannot be an element of other collections.

3.2 Countability

Definition – Countable Set

A set A is countable if there exists a bijection (one-to-one and onto function) f : A → ℕ, or equivalently, its elements can be listed in a sequence a₁, a₂, a₃, …

Example – ℤ (Integers) is Countable

Listing: 0, 1, −1, 2, −2, 3, −3, 4, −4, …

Bijection: f(n) maps natural number n to: 0 if n=0, n/2 if n is even and >0, −(n+1)/2 if n is odd.

Every integer appears exactly once in the list. ✓

Example – ℚ (Rationals) is Countable (Cantor's Zigzag)

Arrange positive rationals in a 2D grid (row i, column j → i/j):

  1/1  1/2  1/3  1/4  ...
  2/1  2/2  2/3  2/4  ...
  3/1  3/2  3/3  3/4  ...
  ...
  

Traverse diagonals: 1/1, 1/2, 2/1, 3/1, 2/2, 1/3, 1/4, 2/3, 3/2, 4/1, …

Skip duplicates (2/2 = 1/1). Every positive rational appears → ℚ⁺ is countable. Adding negatives and 0 keeps it countable. ✓

Theorem – Countable Union of Countable Sets is Countable

If A₁, A₂, A₃, … are all countable sets, then A₁ ∪ A₂ ∪ … is countable.

Proof idea: Apply the same 2D zigzag technique — arrange elements in a grid and traverse diagonally.

3.3 Uncountability

Cantor's Diagonal Argument – ℝ is Uncountable

Theorem: The real numbers in (0,1) cannot be listed — they are uncountably infinite.

Proof:

  1. Suppose for contradiction all reals in (0,1) can be listed: r₁, r₂, r₃, …
  2. Write each as an infinite decimal:
    r₁ = 0.d₁₁ d₁₂ d₁₃ …
    r₂ = 0.d₂₁ d₂₂ d₂₃ …
    r₃ = 0.d₃₁ d₃₂ d₃₃ …
  3. Construct x = 0.x₁x₂x₃… where xᵢ ≠ dᵢᵢ (change each diagonal digit).
  4. x ≠ r₁ (differs at position 1), x ≠ r₂ (position 2), x ≠ rₙ (position n).
  5. So x is not in the list — contradiction! ∴ ℝ is uncountable. ∎
Diagonal Argument Illustrated
r₁ = 0.3141592...   → diagonal digit: 3 → change to 5
r₂ = 0.5000000...   → diagonal digit: 0 → change to 5
r₃ = 0.7182818...   → diagonal digit: 8 → change to 5
r₄ = 0.1428571...   → diagonal digit: 8 → change to 5
  

New number: x = 0.5555… This is NOT equal to any rᵢ in the list (differs at position i). Contradiction!

Practice Questions
Q1. Is the set of all computer programs countable?

Yes! A program is a finite string over a finite character set (ASCII).

The set of all finite strings over a finite alphabet is countable — list them in order of increasing length, then lexicographically.

Deep implication: There are only countably many programs, but uncountably many functions ℕ→ℕ (since 𝒫(ℕ) is uncountable). Therefore, most mathematical functions cannot be computed by any program!

Q2. Show that the power set 𝒫(ℕ) is uncountable.

Suppose 𝒫(ℕ) is countable: list all subsets as S₁, S₂, S₃, …

Define the diagonal set: D = {n ∈ ℕ : n ∉ Sₙ}.

For each n: n ∈ D ↔ n ∉ Sₙ, so D ≠ Sₙ for any n.

But D ⊆ ℕ, so D should appear somewhere in the list. Contradiction!

∴ 𝒫(ℕ) is uncountable.

3.4 Applications in Computability and Automata

The Halting Problem is Undecidable (Turing, 1936)

Claim: No program H can exist that, given any program P and input I, correctly decides whether P halts on I.

  1. Assume H(P, I) → "halts" or "loops" exists.
  2. Construct D(P): run H(P, P); if H says "halts" → D loops forever; if H says "loops" → D halts.
  3. Run D(D): if D halts → H(D,D) said "loops" → D should loop. Contradiction!
    If D loops → H(D,D) said "halts" → D should halt. Contradiction!
  4. ∴ H cannot exist. The Halting Problem is undecidable. ∎
Countability and Formal Languages

Unit 4 – Abstract Algebra

Algebraic structures powering modern cryptography and coding theory.

4.1–4.4 Group Theory: Axioms and Examples

Definition – Group (G, ★)

A group is a set G with a binary operation ★ satisfying exactly four axioms:

AxiomStatementMeaning
G1 – Closure∀ a,b ∈ G: a★b ∈ GOperation stays inside the set
G2 – Associativity(a★b)★c = a★(b★c)Grouping doesn't matter
G3 – Identity∃ e ∈ G: a★e = e★a = aThere is a "do nothing" element
G4 – Inverse∀ a ∈ G, ∃ a⁻¹: a★a⁻¹ = eEvery element is "undoable"

If additionally a★b = b★a for all a,b, the group is Abelian (commutative).

4.2 Additive Group ℤₙ = ({0,1,…,n−1}, +ₙ)

Elements are integers mod n; addition is done modulo n. Identity is 0. Inverse of a is n−a.

Example – ℤ₅ = ({0,1,2,3,4}, +₅)

3 +₅ 4 = 7 mod 5 = 2.   Identity: 0.   Inverse of 3 = 5−3 = 2 (since 3+₅2=5≡0).

This is Abelian and cyclic, |ℤ₅| = 5.

4.3 Multiplicative Group ℤₙ* = ({a : gcd(a,n)=1}, ×ₙ)

Units Group ℤₙ*

Only elements coprime to n (gcd = 1) have multiplicative inverses mod n, so only they form a group.

|ℤₙ*| = φ(n) (Euler's totient function = count of integers from 1 to n coprime to n).

Example: ℤ₁₂* = {1,5,7,11}, φ(12) = 4.

4.4 Other Important Groups

GroupOperationOrderAbelian?
(ℤ, +)Integer additionYes
(ℝ*, ×)Nonzero real multiplicationYes
Sₙ (Symmetric group)Permutation compositionn!No (n≥3)
Dₙ (Dihedral group)Symmetries of regular n-gon2nNo (n≥3)
GL(n,ℝ)Invertible n×n matricesNo (n≥2)
Practice Questions – Groups
Q1. Verify that ({1,−1}, ×) is a group.

Closure: 1×1=1, 1×(−1)=−1, (−1)×(−1)=1. All in {1,−1}. ✓

Associativity: Multiplication is associative. ✓

Identity: 1 is identity: 1×a = a×1 = a. ✓

Inverse: 1⁻¹=1 and (−1)⁻¹=−1 (since (−1)×(−1)=1). ✓

Also commutative → Abelian group. ✓

Q2. Find all elements of ℤ₁₀* and compute φ(10).

ℤ₁₀* = {a : 1 ≤ a ≤ 9, gcd(a,10)=1}

gcd(1,10)=1 ✓, gcd(3,10)=1 ✓, gcd(7,10)=1 ✓, gcd(9,10)=1 ✓

ℤ₁₀* = {1, 3, 7, 9}

φ(10) = φ(2)×φ(5) = 1×4 = 4. So |ℤ₁₀*| = 4. ✓

4.5–4.6 Order of an Element, Cyclic Groups

Order of an Element

The order of element g in group G is the smallest positive integer k such that g^k = e (identity).

Written: ord(g) or |g|. If no such k exists, g has infinite order.

Cyclic Group

G is cyclic if ∃ g ∈ G such that G = {e, g, g², g³, …} = ⟨g⟩.

g is called a generator. Every cyclic group is Abelian.

ℤₙ under addition is always cyclic with generator 1 (or any element coprime to n).

Example – Orders in ℤ₆
ElementSuccessive multiples (mod 6)Order
001
11,2,3,4,5,06 ← generator
22,4,03
33,02
44,2,03
55,4,3,2,1,06 ← generator

ℤ₆ is cyclic: ℤ₆ = ⟨1⟩ = ⟨5⟩.

4.7 Lagrange's Theorem and Corollaries

Lagrange's Theorem

If H is a subgroup of a finite group G, then |H| divides |G|.

Proof idea: The left cosets {gH : g ∈ G} partition G into equal parts of size |H|. So |G| = (number of cosets) × |H|.

Important Corollaries
Practice Questions – Lagrange's Theorem
Q1. In ℤ₇*, what are the possible orders of elements?

|ℤ₇*| = φ(7) = 6. By Lagrange, element orders must divide 6.

Divisors of 6: 1, 2, 3, 6.

Possible orders: 1, 2, 3, or 6.

Q2. Compute 2^100 mod 7 using Fermat's Little Theorem.

p = 7 (prime), 7 ∤ 2. By Fermat: 2^6 ≡ 1 (mod 7).

100 = 6×16 + 4, so 2^100 = (2^6)^16 × 2^4 ≡ 1^16 × 16 ≡ 16 mod 7 ≡ 2 (mod 7).

Answer: 2^100 ≡ 2 (mod 7).

Q3. Prove: the order of every element of S₃ divides 6.

|S₃| = 3! = 6. By Lagrange, the order of ⟨g⟩ (a cyclic subgroup) must divide |S₃| = 6.

Since ord(g) = |⟨g⟩|, it follows that ord(g) | 6 for every g ∈ S₃. ✓

4.8–4.9 Rings and Polynomial Rings

Definition – Ring (R, +, ×)

A ring is a set R with two operations satisfying:

Commutative ring: Also has a×b = b×a. Examples: ℤ, ℤₙ, ℝ[x].

Not commutative: Matrix ring Mₙ(ℝ) for n ≥ 2.

Polynomial Ring R[x]

R[x] = {a₀ + a₁x + a₂x² + ⋯ + aₙxⁿ : aᵢ ∈ R} with standard polynomial addition and multiplication.

GF(2)[x] = polynomials with binary coefficients, used in cryptography and error-correcting codes.

Example – Polynomial Arithmetic in ℤ₂[x]

All coefficients are mod 2 (so 2 ≡ 0, 3 ≡ 1).

(x² + x + 1) + (x + 1) = x² + 2x + 2 = x² (since 2≡0 mod 2)

(x + 1)² = x² + 2x + 1 = x² + 1 (since 2x ≡ 0)

4.10–4.11 Fields and Primitive Elements

Definition – Field

A field is a commutative ring where every nonzero element has a multiplicative inverse.

Equivalently: (F, +) and (F\{0}, ×) are both Abelian groups, with distributivity.

Examples: ℚ, ℝ, ℂ, ℤₚ (p prime), GF(pⁿ) (Galois/Finite Fields).

Note: ℤ is NOT a field (2 has no multiplicative inverse in ℤ).

Primitive Element of GF(q)

The multiplicative group GF(q)* = GF(q)\{0} is cyclic of order q−1.

A primitive element (primitive root) g is a generator: {g¹, g², …, g^(q−1)} = GF(q)*.

Example – Primitive Root mod 7

Is g=3 a primitive root mod 7? ℤ₇* has order 6.

3¹=3, 3²=2, 3³=6, 3⁴=4, 3⁵=5, 3⁶=1 (mod 7)

All 6 nonzero elements of ℤ₇ appear → yes, 3 is a primitive root mod 7! ✓

4.12 Cryptography: DLP and Diffie-Hellman Key Exchange

Discrete Logarithm Problem (DLP)

Problem: Given a prime p, generator g of ℤₚ*, and y = g^x mod p, find x.

Forward direction: Computing g^x mod p is easy (O(log x) via fast exponentiation).

Reverse direction: Given y, finding x is believed to be computationally hard for large p (no polynomial-time algorithm known). This asymmetry is the security basis.

Diffie-Hellman Key Exchange Protocol

Public parameters: prime p, generator g of ℤₚ*.

  1. Alice picks secret a, computes A = g^a mod p, sends A to Bob publicly.
  2. Bob picks secret b, computes B = g^b mod p, sends B to Alice publicly.
  3. Alice computes: K = B^a mod p = g^(ab) mod p.
  4. Bob computes: K = A^b mod p = g^(ab) mod p.
  5. Both share the secret K = g^(ab) mod p without ever transmitting a or b!

Security: An eavesdropper sees g, p, A=g^a, B=g^b but must solve DLP to find K.

Worked Example – Diffie-Hellman

p = 23, g = 5

Alice: a = 6 → A = 5⁶ mod 23 = 15625 mod 23 = 8

Bob: b = 15 → B = 5^15 mod 23 = 19

Alice: K = 19^6 mod 23 = 2

Bob: K = 8^15 mod 23 = 2

Shared secret: K = 2 ✓

Practice Questions – Cryptography
Q1. Why can't an eavesdropper compute the shared key in Diffie-Hellman?

The eavesdropper sees: p, g, A = g^a mod p, B = g^b mod p.

To compute K = g^(ab) mod p, they need either a or b.

Finding a from A = g^a mod p is exactly the Discrete Logarithm Problem, which has no known efficient (polynomial-time) classical algorithm for large p.

Note: Shor's quantum algorithm CAN solve DLP efficiently, which is why post-quantum cryptography (lattice-based, hash-based) is being standardized by NIST.

Q2. Compute 3^(p-1) mod p for p=11 using Fermat's Little Theorem.

By Fermat's Little Theorem: a^(p-1) ≡ 1 (mod p) for prime p and gcd(a,p)=1.

gcd(3,11)=1 and 11 is prime.

3^(11-1) = 3^10 ≡ 1 (mod 11).

Answer: 1. (No computation needed — FLT gives it directly.)

Unit 5 – Advanced Counting

Analyzing algorithms and combinatorics using recurrences and generating functions.

5.1 Recurrence Relations of Recursive Algorithms

What is a Recurrence Relation?

A recurrence relation defines a function T(n) in terms of its values at smaller inputs. Combined with base cases, it uniquely determines the function.

Used to express time complexity of recursive algorithms.

Method 1: Iteration (Unrolling)

Example – Linear Recursion T(n) = T(n−1) + 1

T(1) = 1, T(n) = T(n−1) + 1

  1. T(n) = T(n−1) + 1
  2. = T(n−2) + 2
  3. = T(n−k) + k
  4. At k = n−1: T(1) + (n−1) = 1 + n − 1 = n

T(n) = n = O(n)

Method 2: Characteristic Equation (for linear recurrences)

Fibonacci: F(n) = F(n−1) + F(n−2), F(0)=0, F(1)=1
  1. Assume F(n) = xⁿ. Substitute: xⁿ = xⁿ⁻¹ + xⁿ⁻². Divide by xⁿ⁻²: x² = x + 1.
  2. Characteristic equation: x² − x − 1 = 0.
  3. Roots: \(\varphi = \frac{1+\sqrt{5}}{2} \approx 1.618\) and \(\hat\varphi = \frac{1-\sqrt{5}}{2} \approx -0.618\)
  4. General solution: \(F(n) = A\varphi^n + B\hat\varphi^n\)
  5. Use F(0)=0, F(1)=1 to find A=1/√5, B=−1/√5.
  6. Binet's Formula: \(F(n) = \dfrac{\varphi^n - \hat\varphi^n}{\sqrt{5}}\)

Growth: F(n) = Θ(φⁿ) — exponential!

5.2 Recurrence Relations of Divide & Conquer Algorithms

A D&C algorithm solves a problem of size n by dividing it into a subproblems of size n/b, then spending f(n) work to combine solutions.

T(n) = a · T(n/b) + f(n)
AlgorithmRecurrenceabf(n)Solution
Binary SearchT(n/2) + O(1)12O(1)O(log n)
Merge Sort2T(n/2) + O(n)22O(n)O(n log n)
Strassen (Matrix)7T(n/2) + O(n²)72O(n²)O(n^2.81)

5.3 Master Theorem and Growth of Functions

Master Theorem

For T(n) = a·T(n/b) + f(n) with a ≥ 1, b > 1:

Define the critical exponent: \(c^* = \log_b a\)

CaseCondition on f(n)Conclusion
Case 1f(n) = O(n^(c*−ε)) for ε>0  [f grows slower than n^c*]T(n) = Θ(n^c*)
Case 2f(n) = Θ(n^c* · log^k n) for k≥0  [same order]T(n) = Θ(n^c* · log^(k+1) n)
Case 3f(n) = Ω(n^(c*+ε)) and af(n/b) ≤ cf(n)  [f grows faster]T(n) = Θ(f(n))

Intuition: Case 1: recursion dominates. Case 2: balanced, extra log. Case 3: work at top level dominates.

Applying Master Theorem – Step by Step

Merge Sort: T(n) = 2T(n/2) + n
a=2, b=2 → c* = log₂2 = 1. f(n)=n=Θ(n¹)=Θ(n^c*). Case 2, k=0 → T(n)=Θ(n log n)

Binary Search: T(n) = T(n/2) + 1
a=1, b=2 → c* = log₂1 = 0. f(n)=1=Θ(1)=Θ(n⁰). Case 2, k=0 → T(n)=Θ(log n)

T(n) = 4T(n/2) + n
a=4, b=2 → c* = log₂4 = 2. f(n)=n=O(n^(2−1))=O(n¹). Case 1 → T(n)=Θ(n²)

Asymptotic Notation Reference

NotationMeaningFormal Definition
f = O(g)f ≤ g asymptotically∃c,n₀: f(n) ≤ c·g(n) ∀n≥n₀
f = Ω(g)f ≥ g asymptotically∃c,n₀: f(n) ≥ c·g(n) ∀n≥n₀
f = Θ(g)f and g same ratef=O(g) AND f=Ω(g)
f = o(g)f strictly slowerlim f(n)/g(n) = 0 as n→∞
Practice Questions – Master Theorem
Q1. Solve T(n) = 3T(n/3) + n.

a=3, b=3 → c* = log₃3 = 1. f(n)=n = Θ(n¹) = Θ(n^c*).

Case 2 with k=0: T(n) = Θ(n log n).

Q2. Solve T(n) = 9T(n/3) + n.

a=9, b=3 → c* = log₃9 = 2. f(n)=n = O(n^(2−1)) = O(n^1).

f grows strictly slower than n^c*=n²: Case 1.

T(n) = Θ(n²).

Q3. Solve T(n) = 2T(n/2) + n log n.

a=2, b=2 → c* = 1. f(n) = n log n = Θ(n¹ · log¹n) = Θ(n^c* · log¹n).

Case 2 with k=1: T(n) = Θ(n log² n).

5.4 Generating Functions

Ordinary Generating Function (OGF)

The OGF of sequence a₀, a₁, a₂, … is the formal power series:

\[ A(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1 x + a_2 x^2 + \cdots \]

Key idea: The sequence IS the generating function — encoded as coefficients. We treat this as a formal algebraic object and use algebra to extract information.

Reading off: aₙ = [xⁿ] A(x) (the coefficient of xⁿ in A(x)).

Standard Generating Functions

Sequence aₙGenerating Function A(x)
1, 1, 1, 1, 1, …\(\dfrac{1}{1-x}\)
1, r, r², r³, …\(\dfrac{1}{1-rx}\)
\(\binom{n+k}{k}\) (fixed k)\(\dfrac{1}{(1-x)^{k+1}}\)
Fibonacci: 0,1,1,2,3,5,…\(\dfrac{x}{1-x-x^2}\)
n = 0,1,2,3,…\(\dfrac{x}{(1-x)^2}\)

Operations on Generating Functions

OperationEffect on Sequence
A(x) + B(x)aₙ + bₙ (pointwise sum)
x · A(x)Shift right: 0, a₀, a₁, a₂, …
A(x) · B(x)Convolution: cₙ = Σᵢ aᵢ · bₙ₋ᵢ
A'(x)n · aₙ (multiply each term by its index)
∫A(x)dxaₙ/(n+1) (divide by index+1)

5.5 Applications of Generating Functions in Counting

Example 1 – Stars and Bars via GF

Problem: Number of ways to distribute n identical items into k distinct bins (each bin ≥ 0).

GF for one bin (can hold 0,1,2,… items): \(\sum_{j=0}^{\infty} x^j = \dfrac{1}{1-x}\)

GF for k bins: \(\left(\dfrac{1}{1-x}\right)^k = \dfrac{1}{(1-x)^k}\)

Answer = [xⁿ] \(\dfrac{1}{(1-x)^k} = \dbinom{n+k-1}{k-1}\) ← Stars and Bars!

Example 2 – Coin Change Counting

Problem: Ways to make n cents using 1¢, 2¢, 5¢ coins (unlimited supply).

GF for each coin type: 1/(1−x^denomination)

Combined GF: \(\dfrac{1}{(1-x)(1-x^2)(1-x^5)}\)

Coefficient of xⁿ = number of ways to make n cents.

Example 3 – Bounded Bins

Problem: Distribute n identical items into 3 bins, each holding 0 to 4 items.

GF for one bin: 1 + x + x² + x³ + x⁴ = \(\dfrac{1-x^5}{1-x}\)

Combined: \(\left(\dfrac{1-x^5}{1-x}\right)^3 = \dfrac{(1-x^5)^3}{(1-x)^3}\)

Expand and extract coefficient of xⁿ.

5.6 Applying Generating Functions to Solve Recurrences

Standard Method
  1. Define A(x) = Σ aₙxⁿ.
  2. Multiply the recurrence by xⁿ and sum over valid n values.
  3. Rewrite in terms of A(x) using shifting: Σ aₙ₋₁xⁿ = xA(x), etc.
  4. Solve the resulting algebraic equation for A(x) as a rational function.
  5. Use partial fractions to decompose A(x), then read off coefficients.
Full Example – Fibonacci via GF (Binet's Formula Derivation)

F(n) = F(n−1) + F(n−2), F(0)=0, F(1)=1.

  1. Let F(x) = Σ F(n)xⁿ.
  2. Sum recurrence for n≥2: \(\sum_{n\geq 2}F(n)x^n = \sum_{n\geq 2}F(n-1)x^n + \sum_{n\geq 2}F(n-2)x^n\)
  3. LHS = F(x) − F(0) − F(1)x = F(x) − x
  4. RHS = x·(F(x)−F(0)) + x²·F(x) = xF(x) + x²F(x)
  5. F(x) − x = xF(x) + x²F(x)
  6. F(x)(1 − x − x²) = x
  7. \(\boxed{F(x) = \dfrac{x}{1-x-x^2}}\)
  8. Factor: 1−x−x² = −(x − 1/φ)(x − 1/ψ)... use partial fractions to get \(F(n) = \dfrac{\varphi^n - \hat\varphi^n}{\sqrt{5}}\) ✓
Practice Questions – Generating Functions
Q1. Find the coefficient of x⁵ in 1/(1−x)³.

\(\dfrac{1}{(1-x)^3} = \sum_{n=0}^{\infty} \dbinom{n+2}{2} x^n\)

For n=5: \(\dbinom{7}{2} = 21.\)

Answer: 21.

Combinatorial meaning: ways to distribute 5 identical items into 3 distinct bins = C(7,2) = 21.

Q2. Solve aₙ = 2aₙ₋₁, a₀ = 1 using generating functions.

Let A(x) = Σ aₙxⁿ.

A(x) − a₀ = 2x·A(x) → A(x) − 1 = 2xA(x)

A(x)(1−2x) = 1 → A(x) = 1/(1−2x) = Σ 2ⁿxⁿ

Answer: aₙ = 2ⁿ.

Q3. How many ways to distribute 10 identical candies to 4 children so each gets at least 1?

Substitution: let yᵢ = xᵢ − 1 ≥ 0. Then y₁+y₂+y₃+y₄ = 10 − 4 = 6.

GF = 1/(1−x)⁴. Answer = [x⁶] 1/(1−x)⁴ = C(6+3,3) = C(9,3) = 84.

Answer: 84 ways.

Q4. Solve aₙ − 5aₙ₋₁ + 6aₙ₋₂ = 0, a₀=0, a₁=1 using GFs.

Let A(x) = Σ aₙxⁿ. Multiply recurrence by xⁿ, sum for n≥2:

A(x) − x − 5x·A(x) + 6x²·A(x) = 0

A(x)(1 − 5x + 6x²) = x

A(x) = x / (1−5x+6x²) = x / ((1−2x)(1−3x))

Partial fractions: x/((1−2x)(1−3x)) = A/(1−2x) + B/(1−3x)

Set x=1/2: 1/2 = A(1/2) → A=−1. Set x=1/3: 1/3 = B(1/3) → B=1.

A(x) = −1/(1−2x) + 1/(1−3x) = Σ (−2ⁿ + 3ⁿ)xⁿ

Answer: aₙ = 3ⁿ − 2ⁿ. Verify: a₀=1−1=0 ✓, a₁=3−2=1 ✓.

Q5. Find the GF for the number of ways to partition n into at most 3 parts, each part ≤ 4.

Each part is between 0 and 4, and we have 3 parts (order matters here; if order doesn't matter it's harder).

Treating parts as ordered (compositions): GF for one part = 1 + x + x² + x³ + x⁴ = (1−x⁵)/(1−x).

GF for 3 ordered parts: \(\left(\frac{1-x^5}{1-x}\right)^3\).

Coefficient of xⁿ in this product gives the count. For example, [x⁵] = number of ways = 18 (can verify by enumeration).

Discrete Mathematics Study Notes  •  Units 1–5  •  Logic • Proofs • Set Theory • Abstract Algebra • Advanced Counting

© 2025 @oksaumya  •  All rights reserved.