Discrete Mathematics is the maths behind computer science: logic, sets, functions, counting, proofs and graphs. It is a core BSCS/BSIT course, usually in the 1st or 2nd semester. This guide explains each topic simply, with the key formulas and worked examples you need for exams.
1. Propositional Logic
A proposition is a statement that is either true (T) or false (F), such as "5 is odd". Propositions are combined with logical connectives:
| Connective | Symbol | True when |
|---|---|---|
| Negation (NOT) | ¬p | p is false |
| Conjunction (AND) | p ∧ q | both are true |
| Disjunction (OR) | p ∨ q | at least one is true |
| Implication (IF…THEN) | p → q | false only when p is T and q is F |
| Biconditional (IFF) | p ↔ q | p and q have the same value |
Truth Table for p → q
| p | q | p → q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
- A tautology is always true (e.g. p ∨ ¬p); a contradiction is always false (e.g. p ∧ ¬p).
- Converse of p → q is q → p; contrapositive is ¬q → ¬p. The contrapositive is logically equivalent to the original statement; the converse is not.
- De Morgan’s laws: ¬(p ∧ q) ≡ ¬p ∨ ¬q and ¬(p ∨ q) ≡ ¬p ∧ ¬q.
2. Predicates and Quantifiers
A predicate such as P(x): "x > 3" becomes a proposition when x has a value. ∀x P(x) means "for all x"; ∃x P(x) means "there exists an x". Negation rules: ¬∀x P(x) ≡ ∃x ¬P(x) and ¬∃x P(x) ≡ ∀x ¬P(x).
3. Sets
Example: A = {1, 2, 3, 4} and B = {3, 4, 5}.
- Union A ∪ B = {1, 2, 3, 4, 5}
- Intersection A ∩ B = {3, 4}
- Difference A − B = {1, 2}
- Cardinality |A| = 4
- Power set: a set with n elements has 2ⁿ subsets, so A has 16.
- Inclusion–exclusion: |A ∪ B| = |A| + |B| − |A ∩ B| = 4 + 3 − 2 = 5
4. Relations
A relation R on a set A is a set of ordered pairs. Key properties:
- Reflexive: (a, a) ∈ R for every a
- Symmetric: if (a, b) ∈ R then (b, a) ∈ R
- Antisymmetric: if (a, b) and (b, a) are in R then a = b
- Transitive: if (a, b) and (b, c) are in R then (a, c) ∈ R
A relation that is reflexive, symmetric and transitive is an equivalence relation. One that is reflexive, antisymmetric and transitive is a partial order (e.g. ≤ on numbers).
5. Functions
- One-to-one (injective): different inputs give different outputs.
- Onto (surjective): every element of the codomain is an output of some input.
- Bijective: both one-to-one and onto; only bijections have an inverse.
Example: f(x) = 2x + 1 from integers to integers is one-to-one but not onto (it never gives an even number).
6. Counting
- Sum rule: if a task can be done in m ways or n ways (no overlap), there are m + n ways.
- Product rule: if a task has two steps with m and n ways, there are m × n ways. Example: a PIN of 4 digits has 10⁴ = 10,000 possibilities.
- Permutations: nPr = n! ÷ (n − r)!; combinations: nCr = n! ÷ [r!(n − r)!]
- Pigeonhole principle: if n + 1 objects go into n boxes, at least one box contains two objects. In any group of 13 people, at least two share a birth month.
7. Proof by Mathematical Induction
Claim: 1 + 2 + … + n = n(n + 1) ÷ 2 for all n ≥ 1.
- Base case (n = 1): left side = 1, right side = 1 × 2 ÷ 2 = 1. True.
- Inductive hypothesis: assume 1 + 2 + … + k = k(k + 1) ÷ 2.
- Inductive step: add (k + 1) to both sides: k(k + 1) ÷ 2 + (k + 1) = (k + 1)(k + 2) ÷ 2, which is the formula for n = k + 1.
- So the statement is true for all n ≥ 1.
Other proof methods: direct proof, proof by contradiction and proof by contrapositive.
8. Graph Theory Basics
- A graph G = (V, E) has vertices and edges. The degree of a vertex is the number of edges touching it.
- Handshaking theorem: the sum of all degrees = 2 × (number of edges). So the number of odd-degree vertices is always even.
- A complete graph Kₙ has n(n − 1) ÷ 2 edges.
- A tree with n vertices has exactly n − 1 edges and no cycles.
- An Euler circuit exists in a connected graph when every vertex has even degree.
FAQ
Why is discrete maths important for computer science?
It underpins algorithms, databases (sets and relations), digital logic, cryptography and data structures such as trees and graphs.
What is the difference between a permutation and a combination?
Order matters in a permutation and does not matter in a combination.
Continue with Data Structures Explained Simply or test yourself with the free MCQ practice tests.
0 comments:
Post a Comment