Discrete Mathematics โ€“ University Level โ€“ Pak Notes Hub
๐Ÿ“ University Level โ€” BS CS / BS IT

Discrete Mathematics
Complete Notes

Logic ยท Sets ยท Graph Theory ยท Combinatorics ยท Proofs โ€” All in Easy English

๐Ÿ”ข 14 Units ๐ŸŽ“ University Level ๐Ÿ“Š Examples ๐Ÿ“ Practice Tasks ๐Ÿงฎ Problem Solving
Unit 1

Introduction to Discrete Mathematics

What is Discrete Math and why do we study it?

What is Discrete Mathematics?

Discrete Mathematics is the study of mathematical structures that are fundamentally discrete (separate, distinct) rather than continuous. It deals with objects that can only take specific, separated values.

๐Ÿ’ก Think of discrete vs continuous like this: discrete is like counting people (1, 2, 3...), continuous is like measuring water (1.5 liters, 2.3 liters). Discrete Math deals with countable, distinct items!

Discrete vs Continuous Mathematics

FeatureDiscrete MathematicsContinuous Mathematics
ValuesSeparate, distinct, countableUnbroken, smooth range
ExamplesIntegers: 1, 2, 3, 4...Real numbers: 1.5, 2.73, ฯ€
Graph TypePoints, nodes, discrete stepsSmooth curves, flowing lines
OperationsCounting, listing, logical operationsCalculus, limits, derivatives
Used InComputer Science, algorithms, cryptographyPhysics, engineering, calculus

Why is Discrete Math Important for Computer Science?

  • Algorithm Design โ€” Understanding complexity and efficiency
  • Data Structures โ€” Trees, graphs, and networks
  • Logic & Proofs โ€” Foundation of program correctness
  • Cryptography โ€” Number theory and security
  • Database Theory โ€” Relations and set operations
  • Artificial Intelligence โ€” Logic, probability, graph search
  • Networking โ€” Graph theory for network topology

Main Topics in Discrete Mathematics

Logic
Propositional and predicate logic, truth tables
Sets
Collections of objects, operations, Venn diagrams
Relations & Functions
Mappings between sets, properties
Combinatorics
Counting techniques, permutations, combinations
Graph Theory
Networks, paths, trees, connectivity
Proofs
Mathematical reasoning, induction
โœ๏ธ Practice: Give 3 examples of discrete quantities and 3 examples of continuous quantities from real life. Explain why computer memory is discrete, not continuous.
Unit 2

Propositional Logic

Statements, truth values, and logical operators.

What is a Proposition?

A proposition (or statement) is a declarative sentence that is either true (T) or false (F), but not both. The truth value is either 1 (true) or 0 (false).

Examples of Propositions

StatementProposition?Reason
"2 + 2 = 4"โœ“ YesClearly true
"Paris is the capital of France"โœ“ YesTrue statement
"x + 5 = 10"โœ— NoDepends on value of x
"Close the door!"โœ— NoCommand, not a statement
"What time is it?"โœ— NoQuestion, not a statement
"This sentence is false"โœ— NoParadox โ€” neither true nor false

Logical Operators (Connectives)

OperatorSymbolNameMeaning
NOTยฌ or ~NegationOpposite truth value
ANDโˆงConjunctionBoth must be true
ORโˆจDisjunctionAt least one must be true
IF-THENโ†’ImplicationIf p then q
IF AND ONLY IFโ†”BiconditionalBoth have same truth value

Truth Tables

1. Negation (NOT)

pยฌp
TF
FT

2. Conjunction (AND)

pqp โˆง q
TTT
TFF
FTF
FFF

3. Disjunction (OR)

pqp โˆจ q
TTT
TFT
FTT
FFF

4. Implication (IF-THEN)

p โ†’ q means "if p then q". It's false only when p is true and q is false.

pqp โ†’ q
TTT
TFF
FTT
FFT

5. Biconditional (IF AND ONLY IF)

p โ†” q is true when both have the same truth value.

pqp โ†” q
TTT
TFF
FTF
FFT
๐Ÿ’ก Memory Trick: AND (โˆง) is true only when BOTH are true. OR (โˆจ) is true when AT LEAST ONE is true. Implication (โ†’) is false ONLY when true leads to false.
โœ๏ธ Practice: Construct a truth table for (p โˆง q) โ†’ r. Also, determine if "If it rains, then the ground is wet" is true when: (a) it rains and ground is wet (b) it doesn't rain and ground is dry.
Unit 3

Predicate Logic & Quantifiers

Variables, predicates, and universal/existential quantifiers.

What is Predicate Logic?

Predicate logic (also called first-order logic) extends propositional logic by dealing with statements that contain variables. A predicate is a statement whose truth value depends on one or more variables.

Predicates vs Propositions

TypeExampleExplanation
Proposition"5 is odd"Fixed truth value (True)
Predicate"x is odd"Truth depends on x
PredicateP(x): "x > 10"True if x > 10, false otherwise
PredicateQ(x,y): "x + y = 10"Depends on both x and y

Quantifiers

Quantifiers allow us to make statements about "all" or "some" elements in a domain.

1. Universal Quantifier (โˆ€)

Symbol: โˆ€ (for all, for every)

Meaning: โˆ€x P(x) means "P(x) is true for ALL values of x in the domain"

Example:
โˆ€x (xยฒ โ‰ฅ 0)  means "For all real numbers x, xยฒ is non-negative"
This is TRUE for all real numbers.

โˆ€x (x > 5)  means "For all x, x is greater than 5"
This is FALSE (not all numbers are > 5).

2. Existential Quantifier (โˆƒ)

Symbol: โˆƒ (there exists, for some)

Meaning: โˆƒx P(x) means "P(x) is true for AT LEAST ONE value of x"

Example:
โˆƒx (xยฒ = 16)  means "There exists an x such that xยฒ = 16"
This is TRUE (x = 4 or x = -4).

โˆƒx (xยฒ = -1)  means "There exists a real x such that xยฒ = -1"
This is FALSE for real numbers.

Negation of Quantifiers

StatementNegationExplanation
โˆ€x P(x)โˆƒx ยฌP(x)"Not all" means "at least one is not"
โˆƒx P(x)โˆ€x ยฌP(x)"None exists" means "all are not"

Multiple Quantifiers

Order matters when using multiple quantifiers!

โˆ€x โˆƒy (x + y = 0)
"For every x, there exists a y such that x + y = 0"
TRUE (for any x, we can choose y = -x)

โˆƒy โˆ€x (x + y = 0)
"There exists a y such that for all x, x + y = 0"
FALSE (no single y works for ALL x)

Translating English to Logic

English StatementLogical Form
All students passedโˆ€x (Student(x) โ†’ Passed(x))
Some student failedโˆƒx (Student(x) โˆง Failed(x))
No student cheatedยฌโˆƒx (Student(x) โˆง Cheated(x))
Not all birds can flyยฌโˆ€x (Bird(x) โ†’ CanFly(x))
๐Ÿ’ก Key Rule: โˆ€x usually pairs with โ†’ (implication), while โˆƒx usually pairs with โˆง (and). Example: "All dogs bark" = โˆ€x (Dog(x) โ†’ Barks(x)), "Some cats are black" = โˆƒx (Cat(x) โˆง Black(x))
โœ๏ธ Practice: Translate to logic: (1) "Every number has a successor" (2) "There is a smallest prime number" (3) "Not every equation has a solution". Also find the negation of โˆ€x โˆƒy (x < y).
Unit 4

Sets & Set Operations

Collections of objects and operations on them.

What is a Set?

A set is a well-defined collection of distinct objects, called elements or members. Sets are usually denoted by capital letters (A, B, C) and elements by lowercase letters.

A = {1, 2, 3, 4, 5}
B = {red, blue, green}
C = {x | x is an even number}  โ† set-builder notation

โˆˆ  means "is an element of"
โˆ‰  means "is not an element of"

3 โˆˆ A   (3 is in A)
6 โˆ‰ A   (6 is not in A)

Types of Sets

TypeDefinitionExample
Finite SetHas limited number of elementsA = {1, 2, 3}
Infinite SetHas unlimited elementsโ„• = {1, 2, 3, ...}
Empty SetContains no elementsโˆ… or { }
Singleton SetContains exactly one element{5}
Universal SetContains all elements under considerationU
SubsetAll elements of A are in BA โІ B
Proper SubsetA โІ B but A โ‰  BA โŠ‚ B

Set Operations

1. Union (โˆช)

A โˆช B contains all elements that are in A OR in B (or in both).

A = {1, 2, 3}
B = {3, 4, 5}
A โˆช B = {1, 2, 3, 4, 5}

2. Intersection (โˆฉ)

A โˆฉ B contains only elements that are in BOTH A AND B.

A = {1, 2, 3}
B = {3, 4, 5}
A โˆฉ B = {3}

3. Difference (โˆ’)

A โˆ’ B contains elements in A but NOT in B.

A = {1, 2, 3}
B = {3, 4, 5}
A โˆ’ B = {1, 2}

4. Complement (A' or ฤ€)

A' contains all elements in the universal set U that are NOT in A.

U = {1, 2, 3, 4, 5, 6}
A = {1, 2, 3}
A' = {4, 5, 6}

5. 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| = 2 ร— 2 = 4

Set Identities (Laws)

LawUnion FormIntersection Form
IdentityA โˆช โˆ… = AA โˆฉ U = A
DominationA โˆช U = UA โˆฉ โˆ… = โˆ…
IdempotentA โˆช A = AA โˆฉ A = A
ComplementA โˆช A' = UA โˆฉ A' = โˆ…
CommutativeA โˆช B = B โˆช AA โˆฉ B = B โˆฉ A
Associative(AโˆชB)โˆชC = Aโˆช(BโˆชC)(AโˆฉB)โˆฉC = Aโˆฉ(BโˆฉC)
DistributiveAโˆช(BโˆฉC) = (AโˆชB)โˆฉ(AโˆชC)Aโˆฉ(BโˆชC) = (AโˆฉB)โˆช(AโˆฉC)

De Morgan's Laws for Sets

(A โˆช B)' = A' โˆฉ B'
(A โˆฉ B)' = A' โˆช B'

"The complement of a union is the intersection of complements"
"The complement of an intersection is the union of complements"
๐Ÿ’ก Venn Diagrams help visualize sets! Union combines circles, intersection is the overlap, difference removes one from another, complement is everything outside the circle.
โœ๏ธ Practice: If A = {1,2,3,4}, B = {3,4,5,6}, C = {5,6,7,8}, find: (1) A โˆช B (2) A โˆฉ B (3) A โˆ’ B (4) (A โˆช B) โˆฉ C. Also prove (A โˆฉ B)' = A' โˆช B' using an example.
Unit 5

Relations & Functions

Mappings between sets and their properties.

What is a Relation?

A relation R from set A to set B is a subset of the Cartesian product A ร— B. It shows how elements of A are related to elements of B.

A = {1, 2, 3}
B = {4, 5}
R = {(1,4), (2,5), (3,4)}  โ† relation from A to B

We write: 1 R 4 (1 is related to 4)

Types of Relations

For a relation R on a set A (from A to A):

PropertyDefinitionExample
ReflexiveEvery element relates to itself: โˆ€x (x R x)โ‰ค (every number โ‰ค itself)
SymmetricIf x R y then y R x= (if x = y then y = x)
AntisymmetricIf x R y and y R x, then x = yโ‰ค (if xโ‰คy and yโ‰คx, then x=y)
TransitiveIf x R y and y R z, then x R z< (if x

Equivalence Relation

A relation that is reflexive, symmetric, and transitive is called an equivalence relation.

Example: "=" (equality) is an equivalence relation
- Reflexive: x = x
- Symmetric: if x = y, then y = x
- Transitive: if x = y and y = z, then x = z

What is a Function?

A function f from A to B (written f: A โ†’ B) is a special relation where every element in A is related to EXACTLY ONE element in B.

f: A โ†’ B
A is the domain
B is the codomain
The set of actual output values is the range

Example:
f(x) = xยฒ
Domain: โ„ (all real numbers)
Codomain: โ„
Range: [0, โˆž) (non-negative reals only)

Types of Functions

TypeDefinitionDiagram
One-to-One (Injective)Different inputs โ†’ different outputs
If f(xโ‚) = f(xโ‚‚), then xโ‚ = xโ‚‚
Each output has at most one input
Onto (Surjective)Every element in codomain is an output
Range = Codomain
Every output is used
BijectiveBoth one-to-one AND ontoPerfect pairing โ€” each input has exactly one output, and vice versa

Function Examples

One-to-One but NOT Onto:
f: โ„ โ†’ โ„, f(x) = 2x
One-to-one: different x โ†’ different 2x
Not onto: odd numbers never appear as outputs

Onto but NOT One-to-One:
f: โ„ โ†’ โ„, f(x) = xยฒ
Onto [0,โˆž): all non-negative numbers are outputs
Not one-to-one: f(2) = f(-2) = 4

Bijective:
f: โ„ โ†’ โ„, f(x) = x + 5
One-to-one: different x โ†’ different x+5
Onto: every real number y = x+5 for some x

Composition of Functions

If f: A โ†’ B and g: B โ†’ C, then (g โˆ˜ f): A โ†’ C is defined as (g โˆ˜ f)(x) = g(f(x))

f(x) = x + 3
g(x) = 2x

(g โˆ˜ f)(x) = g(f(x)) = g(x+3) = 2(x+3) = 2x + 6
(f โˆ˜ g)(x) = f(g(x)) = f(2x) = 2x + 3

Note: g โˆ˜ f โ‰  f โˆ˜ g (order matters!)
โœ๏ธ Practice: Let R = {(1,1), (2,2), (1,2), (2,1)} on set {1,2}. Check if R is reflexive, symmetric, and transitive. Also, determine if f(x) = 3x โˆ’ 5 is one-to-one, onto, or bijective from โ„ to โ„.
Unit 6

Mathematical Induction

Proving statements for all natural numbers โ€” the domino effect.

What is Mathematical Induction?

Mathematical induction is a proof technique used to prove statements about all natural numbers (or integers). Think of it like dominoes โ€” if the first falls and each domino knocks down the next, all dominoes will fall!

๐Ÿ’ก Induction has two steps: (1) Base Case โ€” prove it's true for n=1 (first domino falls), (2) Inductive Step โ€” prove if it's true for n=k, then it's also true for n=k+1 (each domino knocks the next).

Principle of Mathematical Induction

To prove a statement P(n) is true for all n โ‰ฅ 1:

  • Step 1 (Base Case): Prove P(1) is true
  • Step 2 (Inductive Hypothesis): Assume P(k) is true for some arbitrary k โ‰ฅ 1
  • Step 3 (Inductive Step): Using the assumption, prove P(k+1) is true
  • Conclusion: By induction, P(n) is true for all n โ‰ฅ 1

Example 1: Sum of First n Natural Numbers

Prove: 1 + 2 + 3 + ... + n = n(n+1)/2

Step 1: Base Case (n=1)
Left side: 1
Right side: 1(1+1)/2 = 1
โœ“ True for n=1

Step 2: Inductive Hypothesis
Assume true for n=k:
1 + 2 + 3 + ... + k = k(k+1)/2

Step 3: Inductive Step (prove for n=k+1)
Need to show: 1 + 2 + ... + k + (k+1) = (k+1)(k+2)/2

Left side:
= [1 + 2 + ... + k] + (k+1)
= k(k+1)/2 + (k+1)           [using hypothesis]
= k(k+1)/2 + 2(k+1)/2
= [k(k+1) + 2(k+1)]/2
= (k+1)(k+2)/2               [factoring]
= Right side  โœ“

Conclusion: By induction, formula is true for all n โ‰ฅ 1.

Example 2: Power Inequality

Prove: 2โฟ > n for all n โ‰ฅ 1

Base Case (n=1):
2ยน = 2 > 1  โœ“

Inductive Hypothesis:
Assume 2^k > k for some k โ‰ฅ 1

Inductive Step (prove 2^(k+1) > k+1):
2^(k+1) = 2 ยท 2^k
        > 2 ยท k         [using hypothesis: 2^k > k]
        = k + k
        โ‰ฅ k + 1        [since k โ‰ฅ 1]
โˆด 2^(k+1) > k+1  โœ“

Conclusion: By induction, 2โฟ > n for all n โ‰ฅ 1.

Strong Induction

In strong induction, we assume P(1), P(2), ..., P(k) are ALL true (not just P(k)), then prove P(k+1).

Regular Induction: Assume P(k) โ†’ Prove P(k+1)
Strong Induction:   Assume P(1)โˆงP(2)โˆง...โˆงP(k) โ†’ Prove P(k+1)

Use strong induction when proving P(k+1) requires
information from multiple previous cases.

Common Mistakes in Induction

  • Forgetting Base Case โ€” Always prove for n=1 (or starting value)
  • Not Using Hypothesis โ€” Must explicitly use P(k) assumption in step 3
  • Proving Wrong Direction โ€” Must prove P(k) โ†’ P(k+1), not the reverse
  • Circular Reasoning โ€” Don't assume what you're trying to prove
โœ๏ธ Practice: Use induction to prove: (1) 1 + 3 + 5 + ... + (2nโˆ’1) = nยฒ (2) 3โฟ > 2n + 1 for all n โ‰ฅ 2. Show all three steps clearly.
Unit 7

Combinatorics โ€” Counting Techniques

Permutations, combinations, and the art of counting.

What is Combinatorics?

Combinatorics is the branch of mathematics concerned with counting, arranging, and combining objects. It answers questions like "How many ways can we arrange these items?" or "How many subsets can we choose?"

Fundamental Counting Principles

1. Addition Principle (OR)

If task A can be done in m ways and task B can be done in n ways, and they CANNOT be done together, then either A OR B can be done in m + n ways.

Example: Travel from City X to City Y
- By train: 3 routes
- By bus: 5 routes
Total ways = 3 + 5 = 8 ways

2. Multiplication Principle (AND)

If task A can be done in m ways and task B can be done in n ways, and both must be done, then A AND B can be done in m ร— n ways.

Example: Password with 1 letter + 1 digit
- Letters: 26 ways
- Digits: 10 ways
Total passwords = 26 ร— 10 = 260

Permutations (Order Matters)

A permutation is an arrangement of objects where ORDER matters.

Permutation of n Objects

Number of ways to arrange n distinct objects = n! (n factorial)

n! = n ร— (n-1) ร— (n-2) ร— ... ร— 2 ร— 1

Example: Arrange 4 books on a shelf
4! = 4 ร— 3 ร— 2 ร— 1 = 24 ways

Permutation of r Objects from n

P(n, r) or nPr = number of ways to arrange r objects chosen from n objects

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

Example: Choose and arrange 3 winners from 10 contestants
P(10, 3) = 10!/(10-3)! = 10!/7! = 10ร—9ร—8 = 720 ways

Combinations (Order Doesn't Matter)

A combination is a selection of objects where ORDER does NOT matter.

C(n, r) or nCr = n!/[r!(n-r)!]

Also written as (n choose r) or โฟCแตฃ

Example: Choose 3 students from 10 for a committee
C(10, 3) = 10!/[3!(10-3)!]
         = 10!/(3!ร—7!)
         = (10ร—9ร—8)/(3ร—2ร—1)
         = 120 ways

Permutation vs Combination

FeaturePermutationCombination
OrderMattersDoes NOT matter
FormulaP(n,r) = n!/(n-r)!C(n,r) = n!/[r!(n-r)!]
ExamplePIN code 1234 โ‰  4321Team {A,B,C} = {C,B,A}
ResultAlways largerAlways smaller
RelationshipP(n,r) = r! ร— C(n,r)

Special Cases

C(n, 0) = 1    (one way to choose nothing)
C(n, n) = 1    (one way to choose everything)
C(n, r) = C(n, n-r)    (symmetry property)

Example: C(10, 3) = C(10, 7) = 120

Permutations with Repetition

When objects are not all distinct:

n!/(nโ‚! ร— nโ‚‚! ร— ... ร— nโ‚–!)

where nโ‚, nโ‚‚, ..., nโ‚– are counts of repeated objects

Example: Arrange letters in "MISSISSIPPI"
Total letters = 11
M:1, I:4, S:4, P:2

Arrangements = 11!/(1!ร—4!ร—4!ร—2!) = 34,650

Common Problem Types

Question TypeUse
Arrange/Order itemsPermutation
Select/Choose items (no order)Combination
Form teams/committeesCombination
Assign ranks/positionsPermutation
Passwords/PINsPermutation with repetition allowed
โœ๏ธ Practice: (1) How many 4-digit PINs can be formed using digits 0-9 with repetition? (2) How many ways can 5 people be seated in a row? (3) From 15 students, how many ways can we select a team of 4? (4) Arrange letters in "BANANA".
Unit 8

Discrete Probability

Calculating chances and likelihood of events.

What is Probability?

Probability measures how likely an event is to occur. It's a number between 0 (impossible) and 1 (certain).

P(Event) = (Number of favorable outcomes) / (Total number of possible outcomes)

P(E) โˆˆ [0, 1]
P(certain event) = 1
P(impossible event) = 0

Basic Probability Example

Rolling a fair die (6 faces: 1,2,3,4,5,6):

P(getting 4) = 1/6
P(getting even) = 3/6 = 1/2    (faces: 2,4,6)
P(getting โ‰ค 6) = 6/6 = 1       (certain)
P(getting 7) = 0/6 = 0         (impossible)

Complement Rule

The probability that an event does NOT occur:

P(not E) = 1 โˆ’ P(E)
or
P(E') = 1 โˆ’ P(E)

Example: P(not getting 4) = 1 โˆ’ 1/6 = 5/6

Addition Rule (OR)

For mutually exclusive events (cannot happen together):

P(A or B) = P(A โˆช B) = P(A) + P(B)

Example: Drawing a card
P(Ace or King) = P(Ace) + P(King)
               = 4/52 + 4/52 = 8/52 = 2/13

For non-mutually exclusive events (can happen together):

P(A or B) = P(A) + P(B) โˆ’ P(A and B)

Example: Drawing a card
P(Heart or King) = P(Heart) + P(King) โˆ’ P(King of Hearts)
                 = 13/52 + 4/52 โˆ’ 1/52
                 = 16/52 = 4/13

Multiplication Rule (AND)

For independent events (one doesn't affect the other):

P(A and B) = P(A โˆฉ B) = P(A) ร— P(B)

Example: Flipping two coins
P(both heads) = P(H on first) ร— P(H on second)
              = 1/2 ร— 1/2 = 1/4

Conditional Probability

Probability of A given that B has occurred:

P(A|B) = P(A โˆฉ B) / P(B)

Example: Two dice rolled, sum is 8
P(first die is 3 | sum is 8)

Outcomes where sum = 8: (2,6),(3,5),(4,4),(5,3),(6,2) = 5 outcomes
Outcomes where first = 3 and sum = 8: (3,5) = 1 outcome

P(first=3 | sum=8) = 1/5

Independent vs Dependent Events

TypeDefinitionExample
IndependentOne event doesn't affect the other
P(A|B) = P(A)
Flipping two coins
DependentOne event affects the other
P(A|B) โ‰  P(A)
Drawing cards without replacement

Expected Value

The average outcome if an experiment is repeated many times:

E(X) = ฮฃ [x ร— P(x)]

Example: Rolling a die
E(X) = 1ร—(1/6) + 2ร—(1/6) + 3ร—(1/6) + 4ร—(1/6) + 5ร—(1/6) + 6ร—(1/6)
     = (1+2+3+4+5+6)/6
     = 21/6 = 3.5
โœ๏ธ Practice: (1) A box has 5 red and 3 blue balls. What's P(red)? (2) If you flip 3 coins, what's P(at least 2 heads)? (3) Two cards drawn without replacement from 52 cards. What's P(both aces)?
Unit 9

Graph Theory Basics

Vertices, edges, and network connections.

What is a Graph?

A graph G = (V, E) is a collection of vertices (nodes) V and edges (connections) E that connect pairs of vertices. Graphs model relationships and networks.

๐Ÿ’ก Real-world graphs: Social networks (friends as vertices, friendships as edges), road maps (cities as vertices, roads as edges), computer networks (devices as vertices, connections as edges).

Graph Terminology

TermDefinition
Vertex (Node)A point in the graph
Edge (Link)Connection between two vertices
Adjacent VerticesTwo vertices connected by an edge
DegreeNumber of edges connected to a vertex
PathSequence of vertices connected by edges
CyclePath that starts and ends at the same vertex
Connected GraphThere's a path between every pair of vertices

Types of Graphs

TypeDescriptionExample
Undirected GraphEdges have no direction (bidirectional)Friendship network
Directed Graph (Digraph)Edges have direction (arrows)Twitter followers
Weighted GraphEdges have associated weights/costsRoad network with distances
Simple GraphNo loops, no multiple edgesMost common type
Complete Graph KnEvery vertex connected to every otherKโ‚„ has 6 edges
Bipartite GraphVertices split into two sets, edges only between setsStudents-Courses matching

Degree of a Vertex

The degree of a vertex is the number of edges connected to it.

In undirected graph:
deg(v) = number of edges at vertex v

In directed graph:
in-degree = number of edges coming IN
out-degree = number of edges going OUT

Handshaking Lemma

The sum of all vertex degrees equals twice the number of edges:

ฮฃ deg(v) = 2|E|

Why? Each edge contributes 1 to the degree of TWO vertices.

Corollary: In any graph, the number of vertices
with odd degree is EVEN.

Paths and Cycles

  • Path: Sequence of vertices where each adjacent pair is connected by an edge
  • Simple Path: No vertex is repeated
  • Cycle: Path that starts and ends at the same vertex
  • Simple Cycle: Cycle with no repeated vertices (except first/last)

Euler and Hamilton Paths

TypeDefinitionExists When
Euler PathPath that visits every EDGE exactly once0 or 2 vertices of odd degree
Euler CircuitEuler path that starts/ends at same vertexAll vertices have even degree
Hamilton PathPath that visits every VERTEX exactly onceNo simple rule (NP-complete)
Hamilton CircuitHamilton path that starts/ends at same vertexNo simple rule

Graph Representation

1. Adjacency Matrix

A matrix where entry (i,j) = 1 if edge exists between vertex i and j, otherwise 0.

Graph: A-B, B-C, A-C

    A  B  C
A [ 0  1  1 ]
B [ 1  0  1 ]
C [ 1  1  0 ]

2. Adjacency List

For each vertex, list its adjacent vertices.

A: [B, C]
B: [A, C]
C: [A, B]
โœ๏ธ Practice: (1) Draw a graph with 5 vertices and 7 edges. Calculate each vertex's degree. (2) Verify the handshaking lemma. (3) Determine if a graph with degrees [2,2,3,3,4] is possible.
Unit 10

Trees

Special graphs โ€” hierarchical structures without cycles.

What is a Tree?

A tree is a connected graph with NO cycles. It's the most fundamental hierarchical structure in computer science.

๐Ÿ’ก Real-world trees: File system directories, organization charts, family trees, decision trees, HTML DOM, binary search trees in databases.

Properties of Trees

  • A tree with n vertices has exactly n โˆ’ 1 edges
  • There is exactly one path between any two vertices
  • Removing any edge disconnects the tree
  • Adding any edge creates exactly one cycle
  • A tree is a minimally connected graph

Tree Terminology

TermDefinition
RootThe topmost vertex (in rooted trees)
ParentVertex directly above another
ChildVertex directly below another
Leaf (Terminal)Vertex with no children
Internal VertexVertex with at least one child
SiblingVertices with the same parent
AncestorAny vertex on path from root to this vertex
DescendantAny vertex in subtree rooted at this vertex
LevelDistance from root (root is level 0)
HeightMaximum level in the tree

Types of Trees

TypeDescription
Binary TreeEach vertex has at most 2 children (left and right)
Full Binary TreeEvery vertex has 0 or 2 children
Complete Binary TreeAll levels filled except possibly the last, filled left to right
Perfect Binary TreeAll internal vertices have 2 children, all leaves at same level
Binary Search Tree (BST)Left child < parent < right child
Spanning TreeSubgraph that includes all vertices and is a tree

Binary Tree Properties

For a binary tree with n vertices:
- Maximum number of vertices at level i = 2^i
- Maximum vertices in tree of height h = 2^(h+1) โˆ’ 1
- Minimum height for n vertices = โŒˆlogโ‚‚(n+1)โŒ‰ โˆ’ 1

For a perfect binary tree:
- Height h โ†’ vertices = 2^(h+1) โˆ’ 1
- Height h โ†’ leaves = 2^h

Tree Traversal Methods

Ways to visit all vertices in a tree:

MethodOrderUse Case
PreorderRoot โ†’ Left โ†’ RightCopy a tree, prefix expression
InorderLeft โ†’ Root โ†’ RightBST gives sorted order
PostorderLeft โ†’ Right โ†’ RootDelete a tree, postfix expression
Level-order (BFS)Level by level, left to rightShortest path, level-wise processing

Spanning Trees

A spanning tree of a connected graph G is a subgraph that:

  • Includes all vertices of G
  • Is a tree (connected, no cycles)
  • Has exactly n โˆ’ 1 edges (where n = number of vertices)

Minimum Spanning Tree (MST)

For a weighted graph, the MST is the spanning tree with minimum total edge weight.

Algorithms to find MST:
1. Kruskal's Algorithm โ€” Sort edges, add smallest without creating cycle
2. Prim's Algorithm โ€” Start from a vertex, grow tree by adding cheapest edge
โœ๏ธ Practice: (1) Draw a binary tree with 7 vertices. Identify root, leaves, and height. (2) For tree with root A, children B,C; B has children D,E; C has child F โ€” write preorder, inorder, and postorder traversals. (3) How many edges in a tree with 15 vertices?
Unit 11

Boolean Algebra

Mathematical foundation of digital logic and computer circuits.

What is Boolean Algebra?

Boolean algebra is a branch of mathematics that deals with variables that have only two possible values: true (1) or false (0). It's the mathematical foundation of digital electronics and computer logic.

Boolean Operations

OperationSymbolNameResult
ANDยท or โˆงConjunction1 only if both are 1
OR+ or โˆจDisjunction1 if at least one is 1
NOT' or ยฌNegationFlips the value

Boolean Algebra Laws

LawAND FormOR Form
Identityx ยท 1 = xx + 0 = x
Null/Dominationx ยท 0 = 0x + 1 = 1
Idempotentx ยท x = xx + x = x
Complementx ยท x' = 0x + x' = 1
Involution(x')' = x
Commutativex ยท y = y ยท xx + y = y + x
Associative(xยทy)ยทz = xยท(yยทz)(x+y)+z = x+(y+z)
Distributivexยท(y+z) = xยทy + xยทzx+(yยทz) = (x+y)ยท(x+z)
Absorptionxยท(x+y) = xx + xยทy = x

De Morgan's Laws

(x ยท y)' = x' + y'
(x + y)' = x' ยท y'

In words:
"The complement of AND is OR of complements"
"The complement of OR is AND of complements"

Simplification Example

Simplify: F = xยทy + xยทy'

Step 1: Factor out x
F = xยท(y + y')

Step 2: Apply complement law: y + y' = 1
F = xยท1

Step 3: Apply identity law: xยท1 = x
F = x

Result: The expression simplifies to just x!

Boolean Functions

A Boolean function maps Boolean inputs to a Boolean output:

f(x, y, z) = xยทy' + x'ยทz

Truth table:
x  y  z | f
0  0  0 | 0
0  0  1 | 1
0  1  0 | 0
0  1  1 | 1
1  0  0 | 1
1  0  1 | 1
1  1  0 | 0
1  1  1 | 0

Canonical Forms

FormDescriptionExample
Sum of Products (SOP)OR of AND terms (minterms)x'y + xy'
Product of Sums (POS)AND of OR terms (maxterms)(x+y)ยท(x'+y')
๐Ÿ’ก Boolean algebra is directly implemented in computer circuits using logic gates (AND, OR, NOT gates). Every computation in a computer ultimately reduces to Boolean operations!
โœ๏ธ Practice: (1) Simplify: F = xยทy + xยทy' + x'ยทy using Boolean laws. (2) Prove De Morgan's law (x+y)' = x'ยทy' using a truth table. (3) Convert F = x'y'z + xyz' to Product of Sums form.
Unit 12

Recurrence Relations

Sequences defined recursively โ€” solving recursive formulas.

What is a Recurrence Relation?

A recurrence relation is an equation that defines a sequence based on previous terms. Each term is expressed as a function of earlier terms.

๐Ÿ’ก Famous example: Fibonacci sequence โ€” each number is the sum of the previous two: F(n) = F(n-1) + F(n-2), with F(0)=0, F(1)=1.

Components of a Recurrence Relation

  • Recurrence equation: The recursive formula
  • Initial conditions: Base case values
Example: a_n = 2ยทa_(n-1) + 3  with a_0 = 1

a_0 = 1               (initial condition)
a_1 = 2ยท1 + 3 = 5
a_2 = 2ยท5 + 3 = 13
a_3 = 2ยท13 + 3 = 29
...

Types of Recurrence Relations

TypeFormExample
Linear Homogeneousa_n = cโ‚ยทa_(n-1) + cโ‚‚ยทa_(n-2)a_n = 3a_(n-1) โˆ’ 2a_(n-2)
Linear Non-Homogeneousa_n = cโ‚ยทa_(n-1) + f(n)a_n = 2a_(n-1) + n
First-OrderDepends on one previous terma_n = 2a_(n-1) + 1
Second-OrderDepends on two previous termsa_n = a_(n-1) + a_(n-2)

Solving Linear Homogeneous Recurrence Relations

For: a_n = cโ‚ยทa_(n-1) + cโ‚‚ยทa_(n-2)

Step 1: Form characteristic equation: rยฒ = cโ‚ยทr + cโ‚‚

Step 2: Solve for roots rโ‚, rโ‚‚

Step 3: General solution depends on roots:

  • Two distinct roots: a_n = Aยทrโ‚โฟ + Bยทrโ‚‚โฟ
  • One repeated root r: a_n = (A + Bยทn)ยทrโฟ

Step 4: Use initial conditions to find A and B

Example: Solve a_n = 5a_(n-1) โˆ’ 6a_(n-2), a_0=1, a_1=4

Step 1: Characteristic equation
rยฒ = 5r โˆ’ 6
rยฒ โˆ’ 5r + 6 = 0
(r โˆ’ 2)(r โˆ’ 3) = 0
rโ‚ = 2, rโ‚‚ = 3

Step 2: General solution (two distinct roots)
a_n = Aยท2โฟ + Bยท3โฟ

Step 3: Apply initial conditions
a_0 = 1: Aยท2โฐ + Bยท3โฐ = 1  โ†’  A + B = 1
a_1 = 4: Aยท2ยน + Bยท3ยน = 4  โ†’  2A + 3B = 4

Solve system:
From first: B = 1 โˆ’ A
Substitute: 2A + 3(1โˆ’A) = 4
           2A + 3 โˆ’ 3A = 4
           โˆ’A = 1
           A = โˆ’1, B = 2

Step 4: Final solution
a_n = โˆ’1ยท2โฟ + 2ยท3โฟ = 2ยท3โฟ โˆ’ 2โฟ

Verify: a_0 = 2ยท1 โˆ’ 1 = 1  โœ“
        a_1 = 2ยท3 โˆ’ 2 = 4  โœ“

Famous Recurrence Relations

SequenceRecurrenceInitialClosed Form
FibonacciF_n = F_(n-1) + F_(n-2)F_0=0, F_1=1F_n = (ฯ†โฟ โˆ’ ฯˆโฟ)/โˆš5
Geometrica_n = rยทa_(n-1)a_0 = aa_n = aยทrโฟ
Arithmetica_n = a_(n-1) + da_0 = aa_n = a + nยทd
Tower of HanoiT_n = 2T_(n-1) + 1T_1 = 1T_n = 2โฟ โˆ’ 1
โœ๏ธ Practice: (1) Solve a_n = 4a_(n-1) โˆ’ 4a_(n-2) with a_0=0, a_1=1. (2) Find closed form for a_n = a_(n-1) + 2 with a_0=3. (3) Verify that F_5 = 5 using Fibonacci recurrence F_n = F_(n-1) + F_(n-2).
Unit 13

Counting Principles & Pigeonhole Principle

Advanced counting techniques and a powerful proof tool.

Inclusion-Exclusion Principle

For counting elements in unions of sets, avoiding double-counting:

For two sets:
|A โˆช B| = |A| + |B| โˆ’ |A โˆฉ B|

For three sets:
|A โˆช B โˆช C| = |A| + |B| + |C|
              โˆ’ |A โˆฉ B| โˆ’ |A โˆฉ C| โˆ’ |B โˆฉ C|
              + |A โˆฉ B โˆฉ C|

Pattern: Add individual, subtract pairs, add triples...

Example: Inclusion-Exclusion

In a class of 50 students:
- 30 study Math
- 25 study Physics
- 10 study both

How many study at least one subject?

|M โˆช P| = |M| + |P| โˆ’ |M โˆฉ P|
        = 30 + 25 โˆ’ 10
        = 45 students

Pigeonhole Principle

Simple version: If n+1 objects are placed into n boxes, then at least one box contains more than one object.

๐Ÿ’ก Think of it like this: If 13 people are in a room, at least 2 were born in the same month (13 people, 12 months = pigeonhole principle!)

Generalized Pigeonhole Principle

If n objects are placed into k boxes, then at least one box contains at least โŒˆn/kโŒ‰ objects.

โŒˆ โŒ‰ is the ceiling function (rounds up)

Example: 50 students, 7 days of the week
At least one day has: โŒˆ50/7โŒ‰ = โŒˆ7.14โŒ‰ = 8 students born on it

Pigeonhole Principle Examples

Example 1: Handshakes
In any group of 6 people, either:
- 3 people mutually know each other, OR
- 3 people are mutual strangers

Example 2: Socks
You have 10 black socks and 10 white socks in a drawer.
How many must you grab (in the dark) to guarantee a matching pair?

Answer: 3 socks
(2 colors = 2 boxes, so 3rd sock must match one)

Example 3: Integers
Among any 5 integers, at least two have the same remainder
when divided by 4.

Proof: 4 possible remainders (0,1,2,3) = 4 boxes
       5 integers = 5 objects
       By pigeonhole: โŒˆ5/4โŒ‰ = 2 must have same remainder

Counting with Restrictions

1. Arrangements with Restrictions

Problem: Arrange 5 people in a row where 2 specific people
must sit together.

Solution: Treat the 2 as one unit
- Units to arrange: 4 (the pair + 3 others) = 4! ways
- Ways to arrange the pair internally = 2! ways
- Total = 4! ร— 2! = 24 ร— 2 = 48 ways

2. Distributing Objects into Boxes

ObjectsBoxesFormula
DistinctDistinctk^n (each object has k choices)
IdenticalDistinctC(n+k-1, k-1) = stars and bars
DistinctIdenticalStirling numbers (complex)
IdenticalIdenticalInteger partitions

Stars and Bars Method

Distributing n identical objects into k distinct boxes:

Number of ways = C(n + k โˆ’ 1, k โˆ’ 1)

Example: Distribute 5 identical candies among 3 children
C(5 + 3 โˆ’ 1, 3 โˆ’ 1) = C(7, 2) = 21 ways

Visual: โ˜…โ˜…โ˜…โ˜…โ˜… with 2 bars | to separate:
โ˜…โ˜…|โ˜…|โ˜…โ˜… means child1 gets 2, child2 gets 1, child3 gets 2
โœ๏ธ Practice: (1) In a class of 40, 25 play cricket, 20 play football, 10 play both. How many play neither? (2) Show that among 13 people, at least 2 share a birth month. (3) Distribute 8 identical books among 4 students using stars and bars.
Unit 14

Proof Techniques

Methods to prove mathematical statements โ€” the foundation of rigorous thinking.

What is a Mathematical Proof?

A proof is a logical argument that establishes the truth of a mathematical statement beyond any doubt. It uses axioms, definitions, and previously proven results.

Types of Proof Techniques

1. Direct Proof

Start with assumptions (hypothesis), use logical steps, arrive at conclusion.

Structure: Assume P is true โ†’ ... logical steps ... โ†’ Therefore Q is true

Example: Prove that if n is even, then nยฒ is even.

Proof:
Assume n is even.
Then n = 2k for some integer k    (definition of even)
nยฒ = (2k)ยฒ = 4kยฒ = 2(2kยฒ)
Since 2kยฒ is an integer, nยฒ = 2m where m = 2kยฒ
Therefore nยฒ is even.  โˆŽ

2. Proof by Contrapositive

To prove P โ†’ Q, instead prove ยฌQ โ†’ ยฌP (contrapositive is logically equivalent)

Example: Prove if nยฒ is odd, then n is odd.

Instead, prove: if n is even, then nยฒ is even
(contrapositive of original statement)

Assume n is even.
n = 2k
nยฒ = 4kยฒ = 2(2kยฒ)  โ† even
Therefore, if n is even, nยฒ is even.

By contrapositive: if nยฒ is odd, then n is odd.  โˆŽ

3. Proof by Contradiction

Assume the statement is FALSE, derive a contradiction, conclude it must be TRUE.

Structure: Assume ยฌP โ†’ ... โ†’ Contradiction! โ†’ Therefore P must be true

Example: Prove โˆš2 is irrational.

Proof by contradiction:
Assume โˆš2 is rational.
Then โˆš2 = p/q where p,q are integers, qโ‰ 0, in lowest terms

โˆš2 = p/q
2 = pยฒ/qยฒ
pยฒ = 2qยฒ    โ† pยฒ is even, so p is even
Let p = 2k
(2k)ยฒ = 2qยฒ
4kยฒ = 2qยฒ
qยฒ = 2kยฒ    โ† qยฒ is even, so q is even

But p and q are both even, contradicting "lowest terms"!
Therefore โˆš2 must be irrational.  โˆŽ

4. Proof by Cases

Break the proof into exhaustive cases, prove each separately.

Example: Prove that nยฒ + n is even for all integers n.

Case 1: n is even
n = 2k
nยฒ + n = (2k)ยฒ + 2k = 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

All cases covered, so nยฒ + n is always even.  โˆŽ

5. Proof by Counterexample

To disprove a universal statement (โˆ€x P(x)), find ONE example where it's false.

Disprove: "All prime numbers are odd"

Counterexample: 2 is prime and even.
Therefore the statement is FALSE.  โˆŽ

6. Mathematical Induction

(Already covered in Unit 6 โ€” used to prove statements for all natural numbers)

Proof Strategies Summary

MethodWhen to UseKey Idea
Direct ProofP โ†’ Q seems straightforwardAssume P, deduce Q
ContrapositiveยฌQ โ†’ ยฌP is easier than P โ†’ QProve equivalent statement
ContradictionExistence proofs, irrationalityAssume ยฌP leads to absurdity
CasesNatural divisions exist (even/odd)Exhaust all possibilities
CounterexampleDisproving universal claimsFind one exception
InductionStatements about all integers โ‰ฅ nBase + inductive step

Common Proof-Writing Tips

  • Start clearly: State what you're proving
  • Use definitions: Apply precise mathematical definitions
  • Show all steps: Don't skip logical leaps
  • Use proper notation: โˆ€, โˆƒ, โ†’, โ‡” correctly
  • End with โˆŽ or QED: Signals proof is complete
  • Check logic: Each step must follow from previous
โœ๏ธ Practice: (1) Prove directly: if n is odd, then n + 1 is even. (2) Prove by contradiction: there are infinitely many prime numbers. (3) Prove by cases: |xy| = |x|ยท|y| for all real numbers x, y.

๐ŸŽ‰ Congratulations!

You have completed the Discrete Mathematics Course by Pak Notes Hub! You now understand Logic, Sets, Graph Theory, Combinatorics, Proofs and more. Best of luck in your exams and future studies! ๐ŸŒŸ

Summary

๐Ÿ“Š Course Summary โ€” 14 Units

Quick reference of all topics covered.

# Unit Key Concepts
1Introduction to Discrete MathDiscrete vs continuous, applications in CS
2Propositional LogicPropositions, truth tables, logical operators (โˆง, โˆจ, โ†’, โ†”)
3Predicate Logic & QuantifiersPredicates, โˆ€ (universal), โˆƒ (existential), negation rules
4Sets & Set OperationsUnion, intersection, difference, complement, Cartesian product, De Morgan's laws
5Relations & FunctionsTypes of relations, equivalence relations, one-to-one, onto, bijective functions
6Mathematical InductionBase case, inductive hypothesis, inductive step, strong induction
7CombinatoricsPermutations P(n,r), combinations C(n,r), counting principles
8Discrete ProbabilityBasic probability, addition rule, multiplication rule, conditional probability, expected value
9Graph Theory BasicsVertices, edges, degree, paths, cycles, Euler and Hamilton paths, graph representation
10TreesTree properties, binary trees, traversal methods (preorder, inorder, postorder), spanning trees
11Boolean AlgebraBoolean operations, laws, De Morgan's laws, simplification, SOP and POS forms
12Recurrence RelationsRecursive sequences, solving linear recurrences, characteristic equations, Fibonacci
13Counting PrinciplesInclusion-exclusion principle, pigeonhole principle, stars and bars method
14Proof TechniquesDirect proof, contrapositive, contradiction, cases, counterexample, induction

๐Ÿ”‘ Key Formulas โ€” Quick Reference

ConceptFormula
PermutationP(n,r) = n!/(nโˆ’r)!
CombinationC(n,r) = n!/[r!(nโˆ’r)!]
Pigeonhole PrincipleโŒˆn/kโŒ‰ objects in at least one box
Inclusion-Exclusion|AโˆชB| = |A| + |B| โˆ’ |AโˆฉB|
Handshaking Lemmaฮฃ deg(v) = 2|E|
Tree Edges|E| = |V| โˆ’ 1
Binary Tree Max Vertices2^(h+1) โˆ’ 1
Stars and BarsC(n+kโˆ’1, kโˆ’1)
ProbabilityP(E) = favorable/total
De Morgan's Laws(AโˆชB)' = A'โˆฉB', (AโˆฉB)' = A'โˆชB'