Complete Student Study Guide


Course Overview

Discrete Structure (BCA151) is the mathematical backbone of computer science. Unlike calculus, which deals with continuous quantities, discrete mathematics concerns structures made of distinct, countable, or finite elements: sets, logical propositions, relations, functions, graphs, trees, and algebraic systems. These structures appear directly in every area of computing: sets model database queries; propositional logic is the hardware of every CPU; graphs model the internet, social networks, and file systems; trees organize every file system and compiler; Boolean algebra is the foundation of digital logic design.

The course runs for 48 teaching hours (3 lecture hours per week plus 3 lab/tutorial hours per week), carrying 3 credits, in Semester 2.


Learning Outcomes

By the end of this course a student should be able to:

  1. Perform and prove set operations using algebraic methods and Venn diagrams.
  2. Construct truth tables and evaluate logical equivalence, tautologies, and contradictions.
  3. Apply rules of inference and proof techniques (direct, indirect, contradiction, induction).
  4. Work with relations, equivalence classes, partial orders, Hasse diagrams, and lattices.
  5. Analyze functions as injective, surjective, or bijective; compute inverse and composition.
  6. Count using the product rule, permutations, combinations, pigeonhole, and inclusion-exclusion.
  7. Apply graph theory concepts: paths, connectivity, traversal, and matrix representation.
  8. Traverse and convert trees; apply binary tree algorithms.
  9. Identify algebraic structures: semigroups, monoids, groups; apply Boolean algebra.

Unit 1: Set Theory

Teaching hours: 6

1.1 Basic Concepts: Sets, Elements, Notation, Cardinality

A set is an unordered collection of distinct objects called elements (or members). Two sets are equal if and only if they contain exactly the same elements.

Notation:

  • Roster (enumeration) notation: lists elements explicitly between curly braces. A = {1, 2, 3, 4}.
  • Set-builder (predicate) notation: defines elements by a property. B = {x | x ∈ ℤ, 1 ≤ x ≤ 4} reads "B is the set of all integers x such that x is between 1 and 4 inclusive."
  • ∈ means "is an element of": 2 ∈ A.
  • ∉ means "is not an element of": 5 ∉ A.

Special sets:

  • ∅ (empty set / null set): a set with no elements. |∅| = 0.
  • ℕ: natural numbers {0, 1, 2, 3, …} (note: some definitions exclude 0).
  • ℤ: all integers.
  • ℝ: all real numbers.
  • U: universal set (all elements under discussion in a given context).

Cardinality |A|: the number of elements in set A. |{a, b, c}| = 3. For infinite sets, cardinality is a more nuanced concept (Cantor's work) but for BCA exam purposes, cardinality refers to the count of elements in a finite set.

1.2 Set Relationships

1.2.1 Subsets

A is a subset of B (written A ⊆ B) if every element of A is also in B.

Formally: A ⊆ B ⟺ ∀x (x ∈ A → x ∈ B)

Example: {1, 2} ⊆ {1, 2, 3, 4} — TRUE. Every element of {1,2} is in {1,2,3,4}.

Note: every set is a subset of itself: A ⊆ A. The empty set is a subset of every set: ∅ ⊆ A.

1.2.2 Proper Subsets

A is a proper subset of B (written A ⊂ B) if A ⊆ B but A ≠ B (there is at least one element in B that is not in A).

1.2.3 Universal Set

The universal set U contains all objects relevant to a given problem. All sets in the discussion are subsets of U.

1.2.4 Complement

The complement of A with respect to U is A' (or Ā or Aᶜ) = {x | x ∈ U and x ∉ A}.

1.2.5 Disjoint Sets

Two sets are disjoint if they share no common elements: A ∩ B = ∅.

1.3 Set Operations

Let U = {1,2,3,4,5,6,7,8}, A = {1,2,3,4}, B = {3,4,5,6}.

1.3.1 Union A ∪ B

All elements in A or B (or both): A ∪ B = {1,2,3,4,5,6}.

1.3.2 Intersection A ∩ B

Only elements in both A and B: A ∩ B = {3,4}.

1.3.3 Difference A − B (or A \ B)

Elements in A but not in B: A − B = {1,2}.

Note: A − B ≠ B − A. B − A = {5,6}.

1.3.4 Complement A'

Elements in U but not in A: A' = {5,6,7,8}.

1.3.5 Symmetric Difference A ⊕ B (or A Δ B)

Elements in A or B but not in both: A ⊕ B = (A − B) ∪ (B − A) = {1,2,5,6}.

Equivalently: A ⊕ B = (A ∪ B) − (A ∩ B).

1.4 Venn Diagrams

A Venn diagram represents sets as circles inside a rectangle (the universal set). Regions represent the results of set operations.

U = rectangle
   _______________
  |   ___   ___  |
  |  / A ∩ /B \  |
  | (  A  |  B ) |
  |  \___/ \___/ |
  |_______________|

The overlapping center region = A ∩ B. Left only = A − B. Right only = B − A. Outside both circles = (A ∪ B)'.

1.5 Set Identities

Identity Name
A ∪ U = U Domination (union)
A ∩ ∅ = ∅ Domination (intersection)
A ∪ ∅ = A Identity (union)
A ∩ U = A Identity (intersection)
A ∪ A = A Idempotent (union)
A ∩ A = A Idempotent (intersection)
(A')' = A Double complement
A ∪ A' = U Complement (union)
A ∩ A' = ∅ Complement (intersection)
A ∪ B = B ∪ A Commutativity
A ∩ B = B ∩ A Commutativity
(A ∪ B)' = A' ∩ B' De Morgan's law
(A ∩ B)' = A' ∪ B' De Morgan's law

Proof of De Morgan's (A ∪ B)' = A' ∩ B' using membership tables:

A B A ∪ B (A ∪ B)' A' B' A' ∩ B'
∈ ∈ ∈ ∉ ∉ ∉ ∉
∈ ∉ ∈ ∉ ∉ ∈ ∉
∉ ∈ ∈ ∉ ∈ ∉ ∉
∉ ∉ ∉ ∈ ∈ ∈ ∈

Swipe to see all columns

Columns (A ∪ B)' and A' ∩ B' are identical → identity proved.

1.6 Cartesian Products

The Cartesian product A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B.

A = {1,2}, B = {x,y}: A × B = {(1,x), (1,y), (2,x), (2,y)}.

|A × B| = |A| × |B|

Ordered pair: (a, b) ≠ (b, a) unless a = b. Order matters, unlike sets.

For three sets: A × B × C consists of ordered triples (a, b, c).

Application: a database table is a subset of the Cartesian product of its column domains. If column "Age" is an integer (domain ℕ) and "Name" is a string, then each row is an ordered pair from ℕ × String.

1.7 Power Sets

The power set of A, written P(A) or 2^A, is the set of all subsets of A.

A = {a, b}: P(A) = {∅, {a}, {b}, {a,b}} — four elements.

|P(A)| = 2^|A|

If |A| = 3, then |P(A)| = 8. If |A| = n, |P(A)| = 2^n.

Why 2^n? Each element of A can either be included (1) or excluded (0) from a subset — giving 2 choices per element, hence 2^n total subsets.

1.8 Applications of Sets

  • Databases: SQL WHERE clauses compute set intersections (AND), unions (OR), and differences (NOT IN).
  • Search engines: indexing uses sets of documents; query AND = intersection; OR = union; NOT = complement.
  • Programming: Python set type supports all operations directly: a | b (union), a & b (intersection), a - b (difference).

Unit 2: Logic and Propositional Calculus

Teaching hours: 8

2.1 Propositions and Logical Operators

A proposition is a declarative statement that is either definitely true (T) or definitely false (F), never both.

  • "2 + 2 = 4" — proposition (T), simple.
  • "Kathmandu is the capital of Nepal" — proposition (T), simple.
  • "If it rains then the match is cancelled" — proposition, compound (two simple propositions joined by implication).
  • "x > 5" — NOT a proposition (truth depends on x; this is a predicate).
  • "What time is it?" — NOT a proposition (a question).

Logical connectives:

Connective Symbol Name Description
NOT ¬ or ~ Negation ¬P is true when P is false
AND ∧ Conjunction P ∧ Q is true only when both P and Q are true
OR ∨ Disjunction P ∨ Q is true when at least one of P, Q is true
Implication → Conditional P → Q is false ONLY when P is true and Q is false
Biconditional ↔ Biconditional P ↔ Q is true when P and Q have the same truth value

Swipe to see all columns

Implication truth table:

P Q P → Q
T T T
T F F
F T T
F F T

Key insight on implication: "If P then Q" is a promise: it is broken only when P is true but Q fails. When P is false, the promise is vacuously satisfied — this is the "paradox of material implication" that confuses many students. Example: "If it rains, the match is cancelled." If it does not rain (P is false), the promise was never tested — the proposition is true regardless of whether the match is played.

2.2 Truth Tables

A truth table exhaustively lists all possible truth-value combinations for the variables in an expression and evaluates the expression for each.

Worked example: Construct the truth table for (P ∧ Q) → (P ∨ R)

Variables: P, Q, R → 2³ = 8 rows.

P Q R P ∧ Q P ∨ R (P ∧ Q) → (P ∨ R)
T T T T T T
T T F T T T
T F T F T T
T F F F T T
F T T F T T
F T F F F T
F F T F T T
F F F F F T

Swipe to see all columns

Result column is all T → this is a tautology.

2.3 Tautologies, Contradictions, and Contingencies

Classification Definition Example
Tautology True for every assignment of truth values P ∨ ¬P
Contradiction False for every assignment P ∧ ¬P
Contingency True for some assignments, false for others P ∧ Q

2.4 Logical Equivalence and Implications

P and Q are logically equivalent (written P ≡ Q or P ⟺ Q) if they have identical truth tables.

Key equivalences (laws of logic):

Law Equivalence
Double negation ¬(¬P) ≡ P
Contrapositive P → Q ≡ ¬Q → ¬P
De Morgan ¬(P ∧ Q) ≡ ¬P ∨ ¬Q
De Morgan ¬(P ∨ Q) ≡ ¬P ∧ ¬Q
Absorption P ∨ (P ∧ Q) ≡ P
Distributive P ∧ (Q ∨ R) ≡ (P ∧ Q) ∨ (P ∧ R)
Implication P → Q ≡ ¬P ∨ Q
Biconditional P ↔ Q ≡ (P → Q) ∧ (Q → P)

Verification by truth table: show that P → Q ≡ ¬P ∨ Q:

P Q P → Q ¬P ¬P ∨ Q
T T T F T
T F F F F
F T T T T
F F T T T

Swipe to see all columns

Columns 3 and 5 match → logically equivalent. ✓

2.5 Predicate Logic and Quantifiers

Predicate: a statement containing a variable whose truth value depends on what the variable represents. P(x): x > 5 — P is a predicate; it becomes a proposition when x is assigned a value.

Universal quantifier ∀ (for all):
∀x P(x) means "P(x) is true for every x in the domain."
Example: ∀x (x² ≥ 0) for x ∈ ℝ — TRUE (the square of every real number is non-negative).

Existential quantifier ∃ (there exists):
∃x P(x) means "there exists at least one x in the domain for which P(x) is true."
Example: ∃x (x² = 4) for x ∈ ℤ — TRUE (x = 2 and x = −2 satisfy this).

Negation of quantifiers:

  • ¬(∀x P(x)) ≡ ∃x ¬P(x) — to disprove "all", find one counterexample.
  • ¬(∃x P(x)) ≡ ∀x ¬P(x) — to disprove "there exists", show it fails for all x.

2.6 Rules of Inference

Rules of inference are valid argument patterns. If the premises (hypothesis) are true, the conclusion must be true.

Rule Form Name
Modus Ponens P, P → Q ⊢ Q ("Affirm the antecedent")
Modus Tollens ¬Q, P → Q ⊢ ¬P ("Deny the consequent")
Hypothetical Syllogism P → Q, Q → R ⊢ P → R Chain rule
Disjunctive Syllogism P ∨ Q, ¬P ⊢ Q Process of elimination
Addition P ⊢ P ∨ Q Weakening
Simplification P ∧ Q ⊢ P —
Conjunction P, Q ⊢ P ∧ Q —

Worked example — Modus Ponens:

  • Premise 1: "If the server is overloaded, it will slow down." (P → Q)
  • Premise 2: "The server is overloaded." (P)
  • Conclusion: "The server will slow down." (Q) ✓

Worked example — Modus Tollens:

  • P → Q: "If this code compiles, it has no syntax errors."
  • ¬Q: "The code has a syntax error."
  • ∴ ¬P: "This code did not compile." ✓

2.7 Proof Methods

Direct Proof

Assume P; derive Q step by step using definitions, axioms, and previously proven theorems.

Example: Prove that the sum of two even integers is even.

  • Let m = 2a and n = 2b (definition of even).
  • m + n = 2a + 2b = 2(a + b).
  • 2(a + b) is divisible by 2 → even. ∎

Indirect Proof (Contrapositive)

To prove P → Q, prove ¬Q → ¬P (the contrapositive).

Example: Prove "if n² is even, then n is even."

  • Prove the contrapositive: if n is odd, then n² is odd.
  • Let n = 2k+1; n² = (2k+1)² = 4k²+4k+1 = 2(2k²+2k)+1 — odd. ∎

Proof by Contradiction (Reductio ad absurdum)

Assume ¬P; derive a contradiction; conclude P must be true.

Example: Prove √2 is irrational.

  • Assume √2 = p/q in lowest terms (p, q integers, gcd(p,q) = 1).
  • 2 = p²/q² → p² = 2q² → p² is even → p is even → p = 2m.
  • (2m)² = 2q² → 4m² = 2q² → q² = 2m² → q² is even → q is even.
  • Both p and q are even, contradicting gcd(p,q) = 1. ∎

Proof by Cases

Divide the domain into exhaustive, mutually exclusive cases; prove the statement for each case.

Proof by Induction

See Unit 4.


Unit 3: Relations and Functions

Teaching hours: 8

3.1 Relations

A binary relation R from set A to set B is a subset of A × B. If (a, b) ∈ R, we write aRb.

Example: A = {1, 2, 3}, B = {1, 4, 9}. R = "a is the square root of b" = {(1,1), (2,4), (3,9)}.

Domain: {a | ∃b (a,b) ∈ R} = {1, 2, 3}.
Range: {b | ∃a (a,b) ∈ R} = {1, 4, 9}.

Special relations on A:

  • Universal relation: U_A = A × A — every element of A is related to every element of A (including itself). Always reflexive.
  • Void (empty) relation: ∅ — no element of A is related to any element of A. Always irreflexive; symmetric and transitive vacuously.

Operations on relations: Given R, S ⊆ A × A:

  • Union: R ∪ S = {(a,b) | (a,b) ∈ R or (a,b) ∈ S}
  • Intersection: R ∩ S = {(a,b) | (a,b) ∈ R and (a,b) ∈ S}
  • Complement: R̄ = (A × A) − R
  • Converse: R⁻¹ = {(b,a) | (a,b) ∈ R} — reverses all pairs.

3.2 Properties of Binary Relations

Let R be a relation on set A (from A to A).

Property Definition Example
Reflexive ∀a ∈ A: (a,a) ∈ R ≤ on ℝ; "is equal to"
Irreflexive ∀a ∈ A: (a,a) ∉ R < on ℝ; "is parent of"
Symmetric (a,b) ∈ R → (b,a) ∈ R "is sibling of"
Antisymmetric (a,b) ∈ R and (b,a) ∈ R → a = b ≤ on ℤ
Transitive (a,b) ∈ R and (b,c) ∈ R → (a,c) ∈ R < on ℝ; "is ancestor of"

3.3 Relation Matrix, Digraph, Partitions, and Equivalence Relations

Relation matrix (Boolean matrix M_R): rows and columns are indexed by A. Entry M[i][j] = 1 if (aᵢ, aⱼ) ∈ R; 0 otherwise.

A = {1,2,3}, R = {(1,1),(1,2),(2,3),(3,1)}:

   1  2  3
1 [1  1  0]
2 [0  0  1]
3 [1  0  0]

Digraph of a relation: nodes represent elements; directed edges represent ordered pairs. (a,b) ∈ R → draw arrow from a to b. A loop at node a represents (a,a).

Equivalence relation: a relation that is reflexive, symmetric, and transitive simultaneously.

Examples of equivalence relations:

  • "Has the same birthday as" on people.
  • "≡ (mod n)" on integers: a ≡ b (mod n) iff n divides (a − b).

Equivalence classes: given an equivalence relation R on A, the equivalence class [a] = {b ∈ A | (a,b) ∈ R} — all elements equivalent to a.

Worked example: R = ≡ (mod 3) on {0,1,2,3,4,5,6,7,8}:

  • [0] = {0, 3, 6} (all divisible by 3)
  • [1] = {1, 4, 7}
  • [2] = {2, 5, 8} These three classes form a partition of the set — they are mutually disjoint and their union is the whole set.

Compatibility relation and maximum compatibility blocks: a relation that is reflexive and symmetric (but not necessarily transitive). A maximum compatibility block is the largest set of elements that are all pairwise compatible.

Composite relation S ∘ R: S ∘ R = {(a,c) | ∃b such that (a,b) ∈ R and (b,c) ∈ S}.

3.4 Transitive Closure

The transitive closure of R, written R* or R⁺, is the smallest transitive relation that contains R.

Warshall's algorithm computes the transitive closure efficiently:

Input: Boolean matrix A for R (n × n)
Initialize: T = A
For k = 1 to n:
  For i = 1 to n:
    For j = 1 to n:
      T[i][j] = T[i][j] OR (T[i][k] AND T[k][j])
Output: T is the path matrix (transitive closure)

Example: n = 3, A = {(1,2),(2,3)}. Matrix:

  1 2 3
1[0 1 0]
2[0 0 1]
3[0 0 0]

After Warshall's: {(1,2),(1,3),(2,3)} — added (1,3) which is the transitive closure.

3.5 Representation of Relations

Already covered in 3.3 (Boolean matrices, digraphs).

3.6 Partial Order Relations, Hasse Diagrams, and Lattices

Partial order: a relation that is reflexive, antisymmetric, and transitive. Written (A, ≤) or (A, R).

Example: divisibility on {1,2,3,4,6,12}. "a divides b" (a | b) is reflexive (a | a), antisymmetric (if a | b and b | a then a = b for positive integers), and transitive (if a | b and b | c then a | c).

Hasse diagram: a compact visual representation of a partial order. Rules:

  1. Place "greater" elements higher.
  2. Draw a line between a and b if a < b and there is no c with a < c < b (direct successors only / cover relation).
  3. Omit arrow heads (direction is "up") and reflexive/transitive edges (they are implied).
Hasse diagram of divisibility on {1,2,3,4,6,12}:

        12
       /  \
      4    6
     /    / \
    2    3
    |   / \
    |  /   \
     \ /     \
      1

Cover edges: 1 < 2, 1 < 3, 2 < 4, 2 < 6, 3 < 6, 4 < 12, 6 < 12. Each node appears once; node 2 is below both 4 and 6, and node 1 is below both 2 and 3.

(12 is at the top; 1 at the bottom. Lines show direct divisibility relationships.)

Chain / totally ordered set: a poset in which every pair of elements is comparable (for all a, b, either a ≤ b or b ≤ a). Example: (ℕ, ≤) is a chain. The divisibility poset above is NOT a chain: 2 and 3 are incomparable.

Minimal vs least element: a minimal element m has no element strictly below it; a least element is below every element. Every least element is minimal, but a poset can have several minimal elements and no least element. Example: in {2,3} under divisibility, both 2 and 3 are minimal and neither is least.

Maximal vs greatest element: dual notions (above vs below). A greatest element is maximal, but maximal need not be greatest.

Well-ordered poset: a totally ordered set in which every non-empty subset has a least element. Example: (ℕ, ≤) is well-ordered; (ℤ, ≤) is not (the subset of negative integers has no least element).

Least upper bound (supremum / join): smallest element ≥ both a and b. In the diagram above, lub(2,3) = 6.

Greatest lower bound (infimum / meet): largest element ≤ both a and b. glb(4,6) = 2.

Lattice: a poset in which every pair of elements has both a lub and a glb. The divisibility poset above is a lattice.

Types of lattices:

  • Complete lattice: every subset has a lub and glb.
  • Distributive lattice: a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c) holds for all a, b, c.
  • Modular lattice: satisfies the modular law: if a ≤ c then a ∨ (b ∧ c) = (a ∨ b) ∧ c. Every distributive lattice is modular, but not conversely.
  • Complemented lattice: every element has a complement (an element whose join with it is 1 and meet with it is 0).
  • Boolean lattice: a complemented distributive lattice — the foundation of Boolean algebra.
  • Pseudo-Boolean lattice: a bounded lattice with a relative pseudocomplement a → b = greatest x such that a ∧ x ≤ b; a Boolean algebra is the special case where every element has a complement.

3.7 Closures and Composition of Relations

Reflexive closure of R: R ∪ {(a,a) | a ∈ A} — add all self-pairs.

Symmetric closure of R: R ∪ R⁻¹ — add the reverse of every pair.

Transitive closure: see 3.4 (Warshall's algorithm).

3.8 Functions

A function f from A to B (written f: A → B) is a special type of relation where every element of A is related to exactly one element of B.

  • Domain: A (the input set).
  • Co-domain: B (the declared output set).
  • Range / Image: {f(a) | a ∈ A} ⊆ B (the actual output values).

Difference between co-domain and range: the co-domain is what you declared the function maps to; the range is what it actually produces. For f: ℝ → ℝ defined by f(x) = x², the co-domain is ℝ but the range is [0, ∞).

3.9 Types of Functions

Type Definition Test
Injective (one-to-one) f(a₁) = f(a₂) → a₁ = a₂ No two inputs map to the same output
Surjective (onto) ∀b ∈ B ∃a ∈ A: f(a) = b Every co-domain element is "hit"
Bijective (one-to-one correspondence) Both injective and surjective Invertible;

Worked example: f: {1,2,3} → {a,b,c,d}, f = {(1,a),(2,b),(3,a)}.

  • Injective? No — f(1) = f(3) = a, two different inputs map to the same output.
  • Surjective? No — d is never the output.
  • Bijective? No.

f: {1,2,3} → {a,b,c}, f = {(1,a),(2,b),(3,c)}:

  • Injective? Yes — each maps to a distinct output.
  • Surjective? Yes — all of {a,b,c} appear in the range.
  • Bijective? Yes. ✓

3.10 Inverse and Composition of Functions

Inverse function f⁻¹: exists only if f is bijective. f⁻¹: B → A swaps domain and range: if f(a) = b then f⁻¹(b) = a.

Composition g ∘ f (or g after f): (g ∘ f)(x) = g(f(x)). First apply f, then apply g.

Example: f(x) = 2x + 1, g(x) = x². (g ∘ f)(x) = g(f(x)) = g(2x+1) = (2x+1)² = 4x² + 4x + 1. (f ∘ g)(x) = f(g(x)) = f(x²) = 2x² + 1.

Note: g ∘ f ≠ f ∘ g in general — composition is not commutative.

3.11 Applications

  • Programming: functions are the mathematical basis of programming functions — referential transparency in functional programming directly captures the mathematical definition.
  • Data mapping: a database join can be modeled as a composition of relations.
  • Relational databases: a foreign key relationship is a function from one table to another.

Unit 4: Mathematical Reasoning, Proof Techniques and Combinatorics

Teaching hours: 6

Mathematical Induction

Principle of Mathematical Induction: to prove P(n) for all natural numbers n ≥ n₀:

  1. Base case: Prove P(n₀) is true.
  2. Inductive step: Assume P(k) is true for some arbitrary k ≥ n₀ (the inductive hypothesis); prove P(k+1) is true.

If both steps succeed, P(n) is true for all n ≥ n₀.

Why it works: imagine an infinite row of dominoes. The base case is "the first domino falls." The inductive step is "if domino k falls, domino k+1 also falls." Together they guarantee all dominoes fall.

Worked example: Prove ∑ᵢ₌₁ⁿ i = n(n+1)/2 for all n ≥ 1.

Base case (n = 1): LHS = 1. RHS = 1(2)/2 = 1. ✓

Inductive step: Assume true for k: ∑ᵢ₌₁ᵏ i = k(k+1)/2.

Show true for k+1: ∑ᵢ₌₁^(k+1) i = ∑ᵢ₌₁ᵏ i + (k+1) = k(k+1)/2 + (k+1) = (k+1)[k/2 + 1] = (k+1)(k+2)/2 ✓

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

Strong Induction

In strong induction, the inductive hypothesis assumes P(j) is true for all j where n₀ ≤ j ≤ k (every case up to k, not just the case k itself). This is useful when proving P(k+1) requires not just P(k) but earlier cases.

Example use: proving every integer n ≥ 2 has a prime factorization — the inductive step may need P(k/p) for some prime p | k, not just P(k-1).

Recursive Definitions

A recursive definition has two parts:

  1. Base case: explicitly defines the first element(s).
  2. Recursive case: defines each subsequent element in terms of earlier ones.

Example — Fibonacci sequence:

  • Base: F(0) = 0, F(1) = 1.
  • Recursive: F(n) = F(n-1) + F(n-2) for n ≥ 2. Gives: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

4.1 Structural Induction

Structural induction proves properties of recursively defined structures (trees, lists, expressions). Instead of induction over integers, induction is over the structure itself:

  • Base case: prove property for the simplest structure.
  • Inductive step: prove that if the property holds for all substructures, it holds for any structure built from them.

Example: prove that a full binary tree with n internal nodes has n+1 leaves.

  • Base: a tree with 1 node (the root, which has no children) has 0 internal nodes and 1 leaf. ✓
  • Step: assume every full binary tree with fewer than n internal nodes has (internal nodes)+1 leaves. Take a full binary tree T with n internal nodes and root r. Since T is full and n > 0, r has two child subtrees T₁ and T₂, both full. Let i₁, i₂ be their internal-node counts; i₁ + i₂ = n − 1 (the root is the remaining internal node). By the inductive hypothesis, T₁ has i₁ + 1 leaves and T₂ has i₂ + 1 leaves. The leaves of T are exactly the leaves of T₁ and T₂, so T has (i₁ + 1) + (i₂ + 1) = i₁ + i₂ + 2 = (n − 1) + 2 = n + 1 leaves. ∎

4.2 Applications

Mathematical induction validates algorithm correctness (loop invariants), series summation formulas, and properties of recursive data structures.

4.3 Basic Counting Principles

Rule of product (multiplication principle): if event A can occur in m ways and event B in n ways independently, then both can occur together in m × n ways.

Example: a password of exactly 3 characters, each a digit (0–9) or uppercase letter (A–Z) — 36 characters total. Number of passwords = 36 × 36 × 36 = 46,656.

Rule of sum (addition principle): if event A can occur in m ways and event B in n ways, and they are mutually exclusive, then A or B can occur in m + n ways.

Example: a committee of 1 person chosen from either 3 engineers or 5 managers — 3 + 5 = 8 ways.

4.4 Permutations and Combinations

Permutations P(n, r): the number of ways to arrange r items chosen from n distinct items where order matters.

P(n, r) = n! / (n − r)!

Factorial notation: n! = n × (n−1) × (n−2) × ⋯ × 1. By convention, 0! = 1.

Combinations C(n, r): the number of ways to choose r items from n distinct items where order does not matter.

C(n, r) = n! / (r! × (n − r)!)

Also written as (n choose r) or ⁿCᵣ.

Key relationship: P(n, r) = C(n, r) × r!

Worked example — passwords: How many 4-character passwords use 4 distinct letters from {A, B, C, D, E}?

  • Order matters (password) → permutation.
  • P(5, 4) = 5! / (5-4)! = 120 / 1 = 120.

Worked example — teams: How many 3-person teams can be formed from 10 people?

  • Order does not matter → combination.
  • C(10, 3) = 10! / (3! × 7!) = (10 × 9 × 8) / (3 × 2 × 1) = 720 / 6 = 120.

4.5 Pigeonhole Principle

Simple pigeonhole principle: if n items are placed in m containers and n > m, then at least one container holds more than one item.

Strong pigeonhole principle: if n items are in m containers, at least one container holds at least ⌈n/m⌉ items.

Worked examples:

  1. In a group of 13 people, at least two must share a birth month. People = 13, months = 12 → by pigeonhole, at least one month has at least 2 people. ✓

  2. In a group of 367 people, at least two must share a birthday. Days in a year = 366 (including Feb 29). 367 > 366 → by the pigeonhole principle, at least two share a birthday. This is a deterministic pigeonhole certainty (not the "birthday paradox," which is a probabilistic result that about 23 people suffice for a 50% chance of a shared birthday).

  3. Drawer problem: a drawer contains 3 red and 3 blue socks (6 total). How many must you draw to guarantee a matching pair? Containers = 2 colors. Draw 3 socks → ⌈3/2⌉ = 2, so 3 ensures at least 2 of one color → 3 draws.

Application in CS: by pigeonhole, any hash function mapping a large domain to a smaller range must have collisions. This is fundamental to understanding hash table design and cryptographic hash function analysis.

4.6 Inclusion-Exclusion Principle

For two sets: |A ∪ B| = |A| + |B| − |A ∩ B|

For three sets: |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |B ∩ C| − |A ∩ C| + |A ∩ B ∩ C|

The rule avoids double-counting elements in intersections.

Worked example: In a class of 50 students, 30 study Maths, 25 study Physics, and 10 study both. How many study Maths or Physics? |M ∪ P| = 30 + 25 − 10 = 45. (5 students study neither.)

CS application: counting the number of integers from 1 to 1000 divisible by 2, 3, or 5 uses inclusion-exclusion over three sets.


Unit 5: Combinatorics and Counting Principles

Teaching hours: 5

This unit reinforces and extends the counting methods from Unit 4. For exam purposes, all topics in Units 4 and 5 are tested together.

Additional practice:

Permutations with repetition: n items taken r at a time with repetition allowed = nʳ. (Each position can independently take any of n values.)

Combinations with repetition (multiset): C(n+r−1, r).

Circular permutations: arranging n distinct objects in a circle = (n−1)! (fix one object, arrange the rest).

Partitioning a set of n distinct objects into groups: covered in combinatorial identities (Stirling numbers — beyond most BCA exam scopes, but be aware).


Unit 6: Graph Theory and Trees

Teaching hours: 12

6.1 Graphs: Definitions and Terminology

A graph G = (V, E) consists of a set of vertices (nodes) V and a set of edges E, where each edge connects two vertices.

Terminology:

  • Adjacent nodes: two vertices connected by an edge.
  • Degree of a vertex: the number of edges incident on it. For a directed graph (digraph): in-degree (edges coming in) and out-degree (edges going out).
  • Loop (sling): an edge from a vertex to itself.
  • Parallel (multiple) edges: more than one edge connecting the same two vertices.
  • Multigraph: a graph with parallel edges.
  • Simple graph: no loops or parallel edges.
  • Null graph: all vertices, no edges.
  • Isolated vertex: a vertex with degree 0.

Handshaking theorem: ∑ deg(v) = 2|E| (the sum of all vertex degrees equals twice the number of edges). Consequence: the number of vertices with odd degree is always even.

Directed graph (digraph): edges have a direction (initiating node → terminating node).

Weighted graph: each edge has a numerical weight (representing cost, distance, or capacity).

Isomorphic graphs: two graphs are isomorphic if there is a bijection between their vertex sets that preserves edges. Isomorphic graphs have the same structure even if drawn differently.

6.2 Subgraphs and Converse

A subgraph H of G contains a subset of V and a subset of E (keeping only edges whose both endpoints are in the subset).

Converse (reversal) of a digraph: reverse the direction of every edge.

6.3 Paths, Simple Paths, Elementary Paths, Cycles

  • Path from u to v: a sequence of vertices u = v₀, v₁, …, vₙ = v where each consecutive pair is connected by an edge.
  • Length of path: number of edges in the path.
  • Simple path (edge-simple): no edge is used more than once.
  • Elementary path (node-simple): no vertex is visited more than once.
  • Cycle (circuit): a path that starts and ends at the same vertex.
  • Elementary cycle: a cycle where no vertex is repeated (except the start/end).
  • Geodesic (shortest path): the minimum-length path between two vertices. The length is the distance between the vertices.

6.4 Reachability

Vertex v is reachable from vertex u if there exists a path from u to v.

Reachable set of vertex u: all vertices reachable from u.

Node base: a subset S of vertices such that every vertex in V is reachable from some vertex in S (a "dominating source set").

Triangle inequality: d(u, w) ≤ d(u, v) + d(v, w) for any vertices u, v, w (where d is the distance).

6.5 Connectedness

Type Definition
Connected (undirected) Every pair of vertices has a path between them
Strongly connected (digraph) Every vertex is reachable from every other vertex
Weakly connected (digraph) The underlying undirected graph is connected
Unilaterally connected (digraph) For every pair u, v: either u is reachable from v or v from u (but not necessarily both)

OS application: in an operating system resource allocation graph, deadlock occurs when a cycle exists in the graph (circular waiting). Graph connectivity analysis detects and helps resolve deadlocks.

6.6 Matrix Representation of Graphs

Adjacency matrix A: n × n matrix where A[i][j] = 1 if there is an edge from vertex i to vertex j; 0 otherwise.

Example: Graph with V = {1,2,3,4}, E = {(1,2),(1,3),(2,4),(3,4)}:

   1 2 3 4
1 [0 1 1 0]
2 [0 0 0 1]
3 [0 0 0 1]
4 [0 0 0 0]

Paths of length n: the entry [i][j] in Aⁿ (the n-th matrix power, using Boolean matrix multiplication) equals the number of paths of length exactly n from vertex i to vertex j.

Path (reachability) matrix: A matrix P where P[i][j] = 1 if there is any path from vertex i to vertex j (regardless of length). Computed using Warshall's algorithm (see Unit 3.4).

Warshall's Algorithm (applied to graphs):

Initialize P = A (adjacency matrix)
For k = 1 to n:
  For i = 1 to n:
    For j = 1 to n:
      P[i][j] = P[i][j] OR (P[i][k] AND P[k][j])

Time complexity: O(n³).

Warshall's algorithm flowchart:

flowchart TD
    A[Start: input adjacency matrix A, n = |V|] --> B[Initialize P = A]
    B --> C[Set k = 1]
    C --> D{k <= n?}
    D -- Yes --> E[Set i = 1]
    E --> F{i <= n?}
    F -- Yes --> G[Set j = 1]
    G --> H{j <= n?}
    H -- Yes --> I[P[i][j] = P[i][j] OR (P[i][k] AND P[k][j])]
    I --> J[j = j + 1]
    J --> H
    H -- No --> K[i = i + 1]
    K --> F
    F -- No --> L[k = k + 1]
    L --> C
    D -- No --> M[Output P = path matrix / transitive closure]
    M --> N[End]

Trace on the example above (k=1):
Check if going through vertex 1 adds any new paths. P[2][3] via k=1: P[2][1] AND P[1][3] = 0 AND 1 = 0 — no change.
After k=1: no new paths through vertex 1 (since vertex 1 has no incoming edges in this directed example).

6.7 Types of Graphs

Type Definition
Simple No loops or parallel edges
Multigraph Parallel edges allowed
Complete (Kₙ) Every pair of distinct vertices is connected; has n(n-1)/2 edges
Bipartite V can be divided into two disjoint sets; edges only between sets
Weighted Edges carry numerical values

6.8 Graph Traversal

Breadth-First Search (BFS)

Explores all neighbors of the current vertex before moving deeper. Uses a queue (FIFO).

BFS(G, start):
  Mark start as visited
  Enqueue start
  While queue is not empty:
    v = Dequeue
    For each neighbor u of v:
      If u not visited:
        Mark u as visited
        Enqueue u

BFS properties: finds shortest path (in unweighted graphs) from the start vertex to all reachable vertices. Time complexity: O(V + E).

Depth-First Search (DFS)

Explores as deep as possible along each branch before backtracking. Uses a stack (LIFO) or recursion.

DFS(G, v):
  Mark v as visited
  For each neighbor u of v:
    If u not visited:
      DFS(G, u)

DFS properties: used for cycle detection, topological sort, finding strongly connected components. Time complexity: O(V + E).

Mnemonic: BFS = neighbors first (like spreading ripples on water); DFS = one path as deep as possible (like following a tunnel until a dead end, then backtracking).

6.9 Trees

A tree is a connected, acyclic undirected graph. Equivalent definition: a connected graph with n vertices and exactly n−1 edges.

Rooted tree: one vertex is designated the root. The root is at level 0.

Terminology:

  • Branch node (internal node): a node with at least one child.
  • Leaf (terminal node): a node with no children.
  • Level of a node: distance from the root.
  • Height of tree: maximum level of any leaf.

6.10 Binary and m-ary Trees

An m-ary tree is a rooted tree where every internal node has at most m children.

A binary tree is an m-ary tree with m = 2 (each node has at most a left child and a right child).

A full (complete) binary tree: every internal node has exactly 2 children. For a full binary tree with i internal nodes: number of leaves = i + 1.

6.11 Converting m-ary Tree to Binary Tree

Left-child right-sibling representation:

  1. The left child of a node in the binary tree is the first (leftmost) child of the node in the original tree.
  2. The right child is the next sibling of the node in the original tree.

This transformation stores any ordered tree as a binary tree without information loss.

6.12 Representation of a Binary Tree

Array representation: for a 1-indexed array, the root is at index 1. For a node at index i: left child is at 2i, right child at 2i+1, parent at ⌊i/2⌋. Efficient for complete binary trees; wastes space for sparse trees.

Linked-list representation:

struct Node {
  int data;
  Node* left;
  Node* right;
};

Each node stores its data and pointers to left and right subtrees. Efficient for sparse trees.

Binary search tree insertion (recursive):

BST-insert(root, key):
  If root is null:
    Return new Node(key)
  If key < root.data:
    root.left = BST-insert(root.left, key)
  Else if key > root.data:
    root.right = BST-insert(root.right, key)
  Return root

Inorder traversal (recursive):

Inorder(node):
  If node is null: Return
  Inorder(node.left)
  Visit(node.data)
  Inorder(node.right)

List-structure applications: representing a binary tree as linked nodes (a record with data and two pointer fields) supports dynamic insertion and deletion without shifting elements. Applications include expression trees, symbol tables, binary search trees for dynamic sets, and file-system directory indexing.

6.13 Tree Traversals

Three depth-first traversals for binary trees:

Traversal Order Use
Inorder Left → Root → Right Gives sorted order for a BST
Preorder Root → Left → Right Copy tree structure; prefix expressions
Postorder Left → Right → Root Delete tree; postfix expressions; evaluate expression trees

Worked example: Binary tree:

      A
     / \
    B   C
   / \
  D   E
  • Inorder: D B E A C
  • Preorder: A B D E C
  • Postorder: D E B C A

Mnemonic for order: "in" = visit root in the middle; "pre" = visit root before children; "post" = visit root after children.

6.14 Applications

  • Networking: shortest-path algorithms (Dijkstra's, Bellman-Ford) operate on weighted graphs.
  • Pathfinding: GPS and game AI use graph traversal.
  • Compiler syntax trees: the parse tree of a program is a tree where traversal gives the program in prefix/infix/postfix notation.
  • File systems: directory structures are trees (or DAGs if symbolic links create cycles).

Unit 7: Algebraic Structures

Teaching hours: 3

7.1 Binary Operations

A binary operation ★ on set S is a function ★: S × S → S that assigns to each ordered pair (a, b) in S × S exactly one element a★b in S.

Closure property: a★b must be in S for all a, b ∈ S. If this holds, S is closed under ★.

Examples:

  • Addition on ℤ is closed: 3 + 5 = 8 ∈ ℤ. ✓
  • Division on ℤ is not closed: 1 / 3 ∉ ℤ. ✗

7.2 Algebraic Systems: Semigroups, Monoids, and Groups

Structure Properties required
Groupoid / Magma Closed under binary operation
Semigroup Closed + Associative
Monoid Semigroup + Identity element
Group Monoid + Every element has an Inverse
Abelian (commutative) group Group + Commutative

Associativity: (a★b)★c = a★(b★c) for all a, b, c ∈ S.

Identity element e: a★e = e★a = a for all a ∈ S.

Inverse of a: element a⁻¹ such that a★a⁻¹ = a⁻¹★a = e.

7.3 Group Theory Basics

Example — (ℤ, +):

  • Closed: ✓ (sum of integers is an integer)
  • Associative: ✓
  • Identity: 0 (a + 0 = a)
  • Inverse of a: −a (a + (−a) = 0)
  • Commutative: ✓ → (ℤ, +) is an abelian group.

Example — (ℕ, +):

  • Identity: 0 ✓
  • Inverse of 3? Would be −3 ∉ ℕ. ✗ → (ℕ, +) is a monoid (not a group).

Example — (ℤ, ×):

  • Identity: 1 ✓
  • Inverse of 3? Would be 1/3 ∉ ℤ. ✗ → (ℤ, ×) is a monoid (not a group).

Example — (GL(2,ℝ), ×): invertible 2×2 real matrices under matrix multiplication.

  • Closed: ✓ (product of invertible matrices is invertible)
  • Associative: ✓ (matrix multiplication is associative)
  • Identity: I₂ = [[1, 0], [0, 1]]
  • Inverse: A⁻¹ exists for every A ∈ GL(2,ℝ) by definition
  • Commutative: ✗ (AB ≠ BA in general) → (GL(2,ℝ), ×) is a non-abelian group.

Example — singular 2×2 real matrices under ×: closed and associative with identity I₂, but singular matrices have no inverse → a monoid, not a group.

7.4 Boolean Algebra

Boolean algebra is an algebraic structure (B, ∧, ∨, ¬, 0, 1) where B = {0, 1} and:

Operation Symbol Description
AND (conjunction / meet) ∧ or · 1 only when both operands are 1
OR (disjunction / join) ∨ or + 1 when at least one operand is 1
NOT (complement) ¬ or ' Flips 0 ↔ 1

Basic postulates (axioms):

  • 0 + 0 = 0; 0 · 0 = 0
  • 0 + 1 = 1; 0 · 1 = 0
  • 1 + 1 = 1; 1 · 1 = 1
  • 0' = 1; 1' = 0

Duality principle: any Boolean identity remains valid if 0 and 1 are swapped and ∧ (·) and ∨ (+) are swapped.

Key Boolean theorems:

Theorem Statement
Idempotent A + A = A; A · A = A
Annihilator A + 1 = 1; A · 0 = 0
Identity A + 0 = A; A · 1 = A
Complement A + A' = 1; A · A' = 0
De Morgan (A + B)' = A' · B'; (A · B)' = A' + B'
Absorption A + (A · B) = A; A · (A + B) = A

Boolean functions: a function f: {0,1}ⁿ → {0,1} defined by a Boolean expression.

Worked simplification: Simplify f = A'B + AB' + AB = A'B + A(B' + B) [distributive: factor A from AB' + AB] = A'B + A·1 [complement law: B' + B = 1] = A'B + A [identity: A·1 = A] = A + B [absorption theorem: A + A'B = A + B, since (A + A')(A + B) = 1·(A + B) = A + B] ∴ f = A + B ✓

Verification: build truth table for A'B + AB' + AB vs A + B — they should match.

7.5 Logic Circuits

Logic gates are physical implementations of Boolean operators:

Gate Boolean operation Symbol
AND gate A · B Curved back, flat front
OR gate A + B Curved both ends (like a shield)
NOT gate (inverter) A' Triangle with a bubble
NAND (A · B)' AND + bubble
NOR (A + B)' OR + bubble
XOR A ⊕ B = A'B + AB' OR with extra curve

Simplifying logic circuits using Boolean algebra: replace complex multi-gate circuits with simpler equivalent ones.

Example: Simplify the circuit for f = (A' + B)' (NOR gate output): By De Morgan: (A' + B)' = A'' · B' = A · B'. This is an AND gate with B inverted.

7.6 Applications

  • Automata theory: state machines are algebraic structures; the powerset of states under concatenation forms a monoid.
  • Logic design: CPU arithmetic units, multiplexers, and memory address decoders are Boolean circuits.
  • Cryptography: group theory underpins RSA, Diffie-Hellman, and elliptic curve cryptography.

Key Terms by Unit

Unit 1: set, element, roster notation, set-builder notation, cardinality, subset, proper subset, universal set, complement, disjoint, union, intersection, difference, symmetric difference, Cartesian product, power set, Venn diagram, De Morgan's laws.

Unit 2: proposition, truth value, negation, conjunction, disjunction, conditional, biconditional, truth table, tautology, contradiction, contingency, logical equivalence, predicate, universal quantifier, existential quantifier, modus ponens, modus tollens, contrapositive, proof by contradiction.

Unit 3: binary relation, domain, range, reflexive, symmetric, antisymmetric, transitive, Boolean matrix, digraph, equivalence relation, equivalence class, partition, Warshall's algorithm, partial order, Hasse diagram, lub, glb, lattice, function, injective, surjective, bijective, composition, inverse.

Unit 4/5: product rule, sum rule, permutation, combination, factorial, pigeonhole principle, inclusion-exclusion, mathematical induction, inductive hypothesis, strong induction, recursive definition.

Unit 6: graph, vertex, edge, degree, adjacency matrix, path, cycle, BFS, DFS, tree, root, leaf, binary tree, inorder, preorder, postorder, Warshall's algorithm, strongly connected, weakly connected.

Unit 7: binary operation, closure, semigroup, monoid, group, identity, inverse, abelian group, Boolean algebra, Boolean function, De Morgan, logic gate.


Practice Questions and Answer Keys

Q1: Given A = {2,4,6,8} and B = {1,2,3,4}, find A ∪ B, A ∩ B, A − B, B − A, and A ⊕ B.

A:

  • A ∪ B = {1,2,3,4,6,8}
  • A ∩ B = {2,4}
  • A − B = {6,8}
  • B − A = {1,3}
  • A ⊕ B = (A − B) ∪ (B − A) = {1,3,6,8}

Q2: Prove by mathematical induction that ∑ᵢ₌₁ⁿ (2i−1) = n² for all n ≥ 1.

A: Base case (n = 1): LHS = 2(1)−1 = 1. RHS = 1² = 1. ✓

Inductive step: Assume ∑ᵢ₌₁ᵏ (2i−1) = k². Show ∑ᵢ₌₁^(k+1) (2i−1) = (k+1)².

∑ᵢ₌₁^(k+1) (2i−1) = ∑ᵢ₌₁ᵏ (2i−1) + (2(k+1)−1) = k² + 2k+1 = (k+1)². ✓ ∎

Q3: Apply Warshall's algorithm to find the transitive closure of R = {(1,2),(2,3),(3,1)} on A = {1,2,3}.

A: Initial matrix:

  1 2 3
1[0 1 0]
2[0 0 1]
3[1 0 0]

k=1: Check paths through vertex 1. P[2][2] = P[2][1] ∨ (P[2][1] ∧ P[1][2]) = 0 ∨ (0∧1)= 0. P[3][2] = P[3][2] ∨ (P[3][1] ∧ P[1][2]) = 0 ∨ (1∧1) = 1. Update: M[3][2] = 1. k=2: P[1][3] = P[1][3] ∨ (P[1][2] ∧ P[2][3]) = 0 ∨ (1∧1) = 1. P[3][3] = P[3][3] ∨ (P[3][2] ∧ P[2][3]) = 0 ∨ (1∧1) = 1. k=3: Several updates — final matrix shows all entries = 1 (all vertices reachable from all others → strongly connected). Transitive closure = A × A (complete relation on A).

Q4: Determine whether f: ℝ → ℝ defined by f(x) = 3x − 2 is injective, surjective, and bijective.

A: Injective: Suppose f(x₁) = f(x₂). Then 3x₁ − 2 = 3x₂ − 2 → x₁ = x₂. ✓ Injective.

Surjective: For any y ∈ ℝ, we need x such that 3x − 2 = y → x = (y+2)/3. Since (y+2)/3 ∈ ℝ for all y ∈ ℝ, every output is achieved. ✓ Surjective.

Bijective: both → ✓ Bijective. The inverse is f⁻¹(y) = (y+2)/3.

Q5: Simplify the Boolean expression f = AB' + A'B + AB using Boolean algebra. Show all steps.

A: f = AB' + A'B + AB = AB' + AB + A'B [commutativity, reorder] = A(B' + B) + A'B [distributive: factor A from first two terms] = A·1 + A'B [complement: B' + B = 1] = A + A'B [identity: A·1 = A]

Now use the absorption law variant: A + A'B = A + B: Proof: (A + A'B) = (A + A')(A + B) [distributive] = 1·(A + B) = A + B.

∴ f = A + B ✓


References

  • Official TU BCA 2025 Curriculum, PDF p. 41–47 (SHA-256: sha256:02eee32d756f2decf7604fad66b99d508744e055f14d4e480fc2a92327b8062a)
  • Rosen, K. H. (2011). Discrete Mathematics and Its Applications (8th ed.). McGraw-Hill.
  • Kolman, B., Busby, R. C., & Ross, S. (2000). Discrete Mathematical Structures (3rd ed.). Prentice Hall.
  • Liu, C. L. (1985). Elements of Discrete Mathematics (2nd ed.). McGraw-Hill.
  • Grimaldi, R. P. Discrete and Combinatorial Mathematics: An Applied Introduction. Pearson.