Discrete StructureUnit 213 min read

Sets, Relations, Functions & Proofs

Unit 2 of Discrete Structure covers set theory (operations, power sets, Cartesian products), relations (equivalence, partial orders), functions (injective/surjective), and proof techniques (direct, contradiction, induction) with real-world applications in databases, networks, and algorithms.

TAKEAWAYS:

  • Sets are collections of distinct objects; operations like union, intersection, and complement are fundamental in logic and databases.
  • Relations model connections (e.g., "friend-of" in social networks) and can be classified as reflexive, symmetric, transitive, or equivalence relations.
  • Functions map inputs to outputs uniquely; injective (one-to-one) and surjective (onto) functions are critical in algorithms and cryptography.
  • Proof techniques (direct, contradiction, induction) are essential for validating mathematical claims, especially in algorithm correctness.
  • Cartesian products and power sets are used in combinatorics and computer science (e.g., state machines, database relations).
  • Hasse diagrams visually represent partial orders, while relation matrices help analyze properties like reflexivity.

1. Sets: Definitions and Operations

A set is a well-defined collection of distinct objects, called elements. Sets are denoted by uppercase letters (e.g., ), and elements by lowercase letters (e.g., ).

  • Notation: means " is an element of ", while means it is not.
  • Set-builder notation: , where is a property (e.g., ).

Key Set Operations

Operation Symbol Definition Example (if , )
Union All elements in or
Intersection Elements in both and
Complement or Elements not in (relative to universal set ) If ,
Difference Elements in but not in
Cartesian Product All ordered pairs where ,
UABC1, 246, 735
A ∩ B ∩ C = ∅ (no common elements)

Visualizing Set Operations

UAB1, 23, 4, 56, 7
A only (elements in A but not in B)

Shaded regions for operations:

  • Union (): Entire diagram (all regions).
  • Intersection (): Overlapping region only.
  • Difference (): Only the left circle (excluding overlap).

Power Set and Cardinality

  • The power set is the set of all subsets of , including the empty set and itself.
    • If , then .
  • Cardinality : Number of elements in . For a finite set, .

Example: If , then has subsets.


2. Real-World Applications of Sets

Example 1: Database Queries (eSewa, Khalti)

  • Union: Combining two sets of users (e.g., active and inactive users) to get all users.
  • Intersection: Finding users who used both eSewa and Khalti in a month.
  • Complement: Identifying users who did not make a transaction in a given period.

Example 2: Network Routing (NTC, Ncell)

  • Cartesian Product: Representing possible paths between routers in a network.
    • If and , then gives all possible ordered connections.

Example 3: E-Commerce Inventory (Daraz)

  • Difference: Items in stock () minus sold items () to track remaining inventory.
  • Power Set: All possible combinations of product bundles (e.g., for discounts).

3. Relations: Definitions and Properties

A relation from set to set is a subset of . If , we write .

Types of Relations

Property Definition Example (if , )
Reflexive Yes (since )
Symmetric If , then No (since but )
Transitive If and , then Yes (no counterexample exists)
Antisymmetric If and , then Yes (only are symmetric pairs)

Equivalence Relations

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

  • Equivalence Classes: Partition into disjoint subsets where all elements are related.
    • Example: on .
      • Equivalence classes: .

Visualization:

123
Equivalence relation R on A = {1, 2, 3} with equivalence classes {1, 2} and {3}

Partial Orders

A relation that is reflexive, antisymmetric, and transitive is a partial order.

  • Hasse Diagram: Visual representation of a partial order (omits redundant edges).
    • Example: , .
      graph TD
          1 --> 2
          1 --> 3

4. Real-World Applications of Relations

Example 1: Social Networks (Pathao, Facebook)

  • Equivalence Relation: "Friends-of-friends" (transitive closure of the "friend" relation).
  • Partial Order: Task dependencies in a project (e.g., "Task A must be completed before Task B").

Example 2: Traffic Routes (Kathmandu Roads)

  • Relation: Roads connecting intersections can be modeled as a relation .
    • If , there is a road from intersection to .
  • Transitive Closure: Finding all possible routes between two points (e.g., Thamel to Lakshmi Path).

Example 3: Database Schema (Banks, NEPSE)

  • Foreign Keys: Relations between tables (e.g., Customer and Account).
    • Example: where means customer owns account .

5. Functions: Definitions and Types

A function assigns to each element of exactly one element of .

  • Domain: (set of inputs).
  • Codomain: (set of possible outputs).
  • Range: Actual outputs .

Types of Functions

Type Definition Example
Injective (One-to-One) (no two inputs map to the same output) (no two values give the same )
Surjective (Onto) Every is mapped by some (range = codomain) (every real has a cube root)
Bijective Both injective and surjective (one-to-one and onto)

Visualizing Functions

flowchart TD
    A["Domain: {1, 2}"] -->|"f"| B["Codomain: {a, b}"]
    1 -->|"f(1) = a"| a
    2 -->|"f(2) = b"| b

Example: Let be defined by , , .

  • Injective? No (both 1 and 3 map to ).
  • Surjective? Yes (both and are covered).

6. Real-World Applications of Functions

Example 1: Encryption (Banks, Ncell)

  • Injective Functions: Used in cryptography (e.g., hashing passwords).
    • Example: . No two passwords should hash to the same value.

Example 2: Mapping Users to Roles (eSewa)

  • Function: , where .
    • If is injective, each user has a unique role.

Example 3: Algorithm Design (Sorting)

  • Bijective Functions: Permutations in sorting algorithms (e.g., swapping elements in a list).

7. Proof Techniques

1. Direct Proof

Prove by assuming is true and showing must follow. Example: Prove: If is even, then is even.

  • Proof: Let . Then , which is even.

2. Proof by Contradiction

Assume and show it leads to a contradiction. Example: Prove: is irrational.

  • Proof: Assume (lowest terms). Then , so is even ⇒ is even ⇒ . Substituting: ⇒ , so is even. But this contradicts being in lowest terms.

3. Mathematical Induction

Prove a statement for all by:

  1. Base Case: Show is true.
  2. Inductive Step: Assume is true (inductive hypothesis) and prove . Example: Prove: .
  • Base Case (n=1): ✓
  • Inductive Step: Assume true for . Then for : ✓ Thus, by induction, the formula holds for all .

8. Exam Tip

  1. Sets:

    • Memorize Venn diagrams for operations (union, intersection, complement).
    • For power sets, recall .
    • Cartesian product is often tested in relation to functions (e.g., is a subset of ).
  2. Relations:

    • Properties (reflexive, symmetric, transitive) are frequently asked. Use examples to test them.
    • Equivalence relations and partial orders are key. Draw Hasse diagrams for partial orders.
    • Relation matrices (adjacency matrices) are useful for analyzing properties programmatically.
  3. Functions:

    • Injective/Surjective/Bijective: Know the definitions and how to test them.
    • Pigeonhole Principle: If and , then cannot be injective.
  4. Proofs:

    • Direct proofs are straightforward but require logical steps.
    • Contradiction is powerful for "proving impossibility" (e.g., irrationality).
    • Induction is essential for recursive definitions (e.g., sequences, algorithms).
    • Always write "Assume..." and "Thus..." clearly in proofs.
  5. Common Pitfalls:

    • Confusing subset () with element ().
    • Forgetting reflexivity in relations (e.g., must be included).
    • Misapplying Cartesian product (it’s ordered pairs, not just combinations).

9. Worked Example: Real-World Problem

Problem: In a small town, there are 3 bus routes:

  • Route 1: Thamel ↔ Lakshmi Path
  • Route 2: Thamel ↔ Garden of Dreams
  • Route 3: Lakshmi Path ↔ Garden of Dreams

Model this as a relation and determine if it is transitive.

Solution:

  1. Let .
  2. The relation (direct bus routes) is:
  3. Check Transitivity:
    • Is and ⇒ ? Yes (since ).
    • Is and ⇒ ? Yes.
    • All other combinations also satisfy transitivity.
    • Conclusion: is transitive.

Visualization:

LTG
Transitive relation R on {L, T, G} (all transitive pairs shown)

Application: This model helps the NTC optimize routes by identifying redundant or missing connections for efficiency. For example, if is already covered, adding a direct route might be unnecessary.

Based on the TU BIM syllabus for Discrete Structure (IT235), unit 2.

Discussion

Loading…