BIT152 Discrete Structure

Discrete StructureUnit 99 min read

Relations & Functions: Types, Representations & Applications

Unit 9 of Discrete Structure covers relations (reflexive, symmetric, transitive, equivalence), functions (injective, surjective, bijective), their representations (matrices, graphs, arrows), and real-world applications in algorithms, databases, and cryptography—with visual proofs, matrix examples, and exam-focused prob

TAKEAWAYS:

  • Relations are defined by ordered pairs and classified by properties (reflexive/symmetric/transitive); equivalence relations partition sets into disjoint subsets.
  • Functions map inputs to outputs uniquely and are categorized by injectivity (one-to-one), surjectivity (onto), and bijectivity (both).
  • Matrix representation of relations uses binary entries (1/0) to encode membership in .
  • Graph representation visualizes relations as directed edges between nodes, critical for pathfinding (e.g., NTC’s network routing).
  • Recursive functions (e.g., Fibonacci) define outputs based on prior values; mathematical induction proves their correctness.
  • Real-world ties: Khalti’s transaction validation uses injective functions; Pathao’s ride-matching relies on bipartite graphs (relations between drivers and passengers).

1. Relations: Definitions and Properties

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

Key Properties of Relations

A relation on a set can have these properties:

Property Definition Example (on )
Reflexive is reflexive.
Symmetric If , then . is symmetric.
Transitive If and , then . is transitive.
Equivalence Reflexive, symmetric, and transitive. (if ).

Equivalence Relations and Partitions

An equivalence relation partitions into equivalence classes .

UKathmandu ValleyKathmandu, Lalitpur, Bhaktapur
Partition of cities into equivalence classes (Kathmandu Valley)

Example (Nepali Voting Districts): Let and . Then:

  • (all in Kathmandu Valley).
  • This is an equivalence relation because it is reflexive, symmetric, and transitive.
graph TD
    A["Kathmandu"] --> B["Lalitpur"]
    B --> A
    A --> C["Bhaktapur"]
    C --> A
Equivalence classes merge all cities in the same valley.

2. Functions: Types and Representations

A function assigns exactly one output to each input .

Types of Functions

Type Definition Example (with , )
Injective (1-1) . , (no two inputs map to same output).
Surjective (Onto) Every is mapped by some . , (but is unmapped).
Bijective Both injective and surjective. , , , .
Identity for all . , .

Visualizing Injectivity/Surjectivity:

UAB1, 2a, b, c
Surjective (left): c is unmapped. Bijective (right): all mapped uniquely.

Matrix Representation of Relations

For and , the relation matrix is:

1,1,000,1,111,0,02
Adjacency matrix for Ashish (A), Bikram (B), Chetan (C) friendship relation (A→B, A→C)

Example (Past Exam Question): Given , , and , the matrix is: Explanation:

  • ? No → .
  • ? No → (but wait: the relation is , so for and , is false → . Correction: The relation is , so:
    • ? No →
    • ? No →
    • ? Yes →
    • ? No →
    • ? Yes →
    • ? Yes →

Corrected Matrix:


3. Graph Representation of Relations

Relations can be visualized as directed graphs where nodes are elements and edges represent .

Example (Friendship Relation): Let and . If Ashish is friends with Bikram and Chetan, but Bikram and Chetan are not friends:

graph TD
    A["Ashish"] --> B["Bikram"]
    A --> C["Chetan"]
This graph shows the relation .

4. Recursive Functions and Induction

A recursive function defines in terms of for .

Example (Fibonacci): Trace for :

Proof by Induction (Example): Claim: , where and . Base Cases:

  • : .
  • : .

Inductive Step: Assume true for and . Show for :


5. Real-World Applications

1. Khalti’s Transaction Validation (Injective Functions)

Khalti uses injective functions to assign unique transaction IDs. If two transactions had the same ID, the system would fail to distinguish them. For example:

  • Input: user_id + amount + timestamp.
  • Output: A 64-bit hash (e.g., SHA-256).
  • Why injective? No two distinct inputs produce the same hash (collision-resistant).

2. Pathao’s Ride-Matching (Bipartite Graphs)

Pathao’s algorithm matches drivers to passengers using a bipartite graph:

  • Left nodes: Drivers (with location, vehicle type).
  • Right nodes: Passengers (with pickup/drop locations).
  • Edges: Possible matches (e.g., driver’s location ≤ 500m from passenger).
graph LR
    D1["Driver 1"] -- "Distance ≤ 500m" --> P1["Passenger 1"]
    D1 -- "Distance ≤ 500m" --> P2["Passenger 2"]
    D2["Driver 2"] -- "Distance ≤ 500m" --> P2

Pathao’s algorithm finds a maximum matching in this graph to minimize wait times.

3. NTC’s Network Routing (Transitive Closure)

The Nepal Telecommunications Company (NTC) uses transitive closure to determine if two cities are connected via fiber optics. For example:

  • Let and .
  • If , then the transitive closure adds .

Matrix for Transitive Closure: Original : Transitive closure :


6. Exam Tips

  1. For relations:

    • Always check all three properties (reflexive/symmetric/transitive) for equivalence relations.
    • Matrix questions: Label rows/columns clearly (e.g., ) and fill 1/0 correctly.
    • Graph questions: Draw directed edges and label them with the relation (e.g., "is parent of").
  2. For functions:

    • Injective? Use the "horizontal line test" (no two inputs share an output).
    • Surjective? Ensure every element in is covered.
    • Bijective? Both injective and surjective.
    • Identity function: Always maps .
  3. Recursive functions:

    • Trace step-by-step for small values (e.g., to ).
    • Induction proofs: Show base case(s) and assume the inductive hypothesis for the step.
  4. Common pitfalls:

    • Off-by-one errors in recursive definitions (e.g., vs. ).
    • Confusing symmetric/transitive: Symmetric requires ; transitive requires chaining and to .
    • Matrix dimensions: If has elements and has elements, the matrix is .

Based on the TU BIT syllabus for Discrete Structure (BIT152), unit 9.

Discussion

Loading…