ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCSI-303Relations And Function…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    CSI-303

    Discrete Structures

    Progress0 / 21 done
    Topics21
    1Introduction to Logic and Proofs2Direct Proofs3Proof by Contradiction4Sets5Combinatorics6Sequences7Formal Logic8Propositional and Predicate Calculus9Methods of Proof10Mathematical Induction and Recursion11Loop Invariants12Relations and Functions13Pigeonhole Principle14Trees and Graphs15Elementary Number Theory16Optimization and Matching17Fundamental Structures18Functions19Relations (Recursions)20Cardinality and Countability21Probabilistic Methods
    13 min read
    Topic 12 of 21
    Topic Study Note Illustration
    12

    Relations and Functions

    In Discrete Structures , relations and functions are fundamental concepts used to describe how elements from one set are related to elements in another set (or the...

    Relations and Functions

    In Discrete Structures, relations and functions are fundamental concepts used to describe how elements from one set are related to elements in another set (or the same set). These concepts are widely used in mathematics, computer science, and logic, particularly for modeling systems, algorithms, and databases.

    1. Relations

    A relation is a way to describe a connection or association between elements of two sets. It generalizes the concept of a function but is more flexible.

    Definition of a Relation:

    A relation RRR from a set AAA to a set BBB is a subset of the Cartesian product A×BA \times BA×B. This means that each relation RRR consists of ordered pairs (a,b)(a, b)(a,b) where a∈Aa \in Aa∈A and b∈Bb \in Bb∈B. If (a,b)∈R(a, b) \in R(a,b)∈R, we say that aaa is related to bbb under RRR, and we write aRba R baRb.

    • Notation: aRba R baRb means that aaa is related to bbb.
    • Example: Consider the set A={1,2,3}A = \{1, 2, 3\}A={1,2,3} and B={a,b,c}B = \{a, b, c\}B={a,b,c}. A relation RRR from AAA to BBB could be: R={(1,a),(2,b),(3,c)}R = \{(1, a), (2, b), (3, c)\}R={(1,a),(2,b),(3,c)} This means that element 111 in set AAA is related to aaa in set BBB, element 222 in AAA is related to bbb in BBB, and so on.

    Types of Relations:

    Relations can have additional properties, such as:

    • Reflexive: A relation RRR on a set AAA is reflexive if, for every element a∈Aa \in Aa∈A, aRaa R aaRa. In other words, each element is related to itself.

      • Example: R={(1,1),(2,2),(3,3)}R = \{(1, 1), (2, 2), (3, 3)\}R={(1,1),(2,2),(3,3)} is reflexive for A={1,2,3}A = \{1, 2, 3\}A={1,2,3}.
    • Symmetric: A relation RRR on a set AAA is symmetric if, for all a,b∈Aa, b \in Aa,b∈A, whenever aRba R baRb, then bRab R abRa.

      • Example: If R={(1,2),(2,1)}R = \{(1, 2), (2, 1)\}R={(1,2),(2,1)}, then it is symmetric because (1,2)(1, 2)(1,2) implies (2,1)(2, 1)(2,1) and vice versa.
    • Transitive: A relation RRR on a set AAA is transitive if, for all a,b,c∈Aa, b, c \in Aa,b,c∈A, whenever aRba R baRb and bRcb R cbRc, then aRca R caRc.

      • Example: R={(1,2),(2,3),(1,3)}R = \{(1, 2), (2, 3), (1, 3)\}R={(1,2),(2,3),(1,3)} is transitive, because 1R21 R 21R2 and 2R32 R 32R3 imply 1R31 R 31R3.
    • Anti-symmetric: A relation RRR on a set AAA is anti-symmetric if, for all a,b∈Aa, b \in Aa,b∈A, whenever aRba R baRb and bRab R abRa, then a=ba = ba=b.

      • Example: R={(1,2),(2,1)}R = \{(1, 2), (2, 1)\}R={(1,2),(2,1)} is not anti-symmetric because 1≠21 \neq 21=2, but (1,2)(1, 2)(1,2) and (2,1)(2, 1)(2,1) are in the relation. On the other hand, the relation {(1,2),(2,2)}\{(1, 2), (2, 2)\}{(1,2),(2,2)} is anti-symmetric.
    • Equivalence Relation: A relation that is reflexive, symmetric, and transitive is called an equivalence relation. An example of an equivalence relation is the "equals" relation on integers, where a≡ba \equiv ba≡b modulo nnn.

    • Partial Order: A relation that is reflexive, transitive, and anti-symmetric is a partial order. An example of a partial order is the subset relation on sets, ⊆\subseteq⊆, where A⊆BA \subseteq BA⊆B means AAA is a subset of BBB.


    2. Functions

    A function is a special type of relation where each element in the domain (set AAA) is related to exactly one element in the codomain (set BBB).

    Definition of a Function:

    A function fff from a set AAA to a set BBB is a relation where each element a∈Aa \in Aa∈A is associated with a unique element b∈Bb \in Bb∈B. This is written as:

    f:A→Bf: A \to Bf:A→B

    If f(a)=bf(a) = bf(a)=b, then aaa is mapped to bbb under the function fff.

    • Notation: The notation f(a)=bf(a) = bf(a)=b means that fff maps aaa from set AAA to bbb in set BBB.
    • Example: Let A={1,2,3}A = \{1, 2, 3\}A={1,2,3} and B={a,b,c}B = \{a, b, c\}B={a,b,c}, and define the function fff as: f={(1,a),(2,b),(3,c)}f = \{(1, a), (2, b), (3, c)\}f={(1,a),(2,b),(3,c)} This means that f(1)=af(1) = af(1)=a, f(2)=bf(2) = bf(2)=b, and f(3)=cf(3) = cf(3)=c.

    Types of Functions:

    • Injective (One-to-One): A function f:A→Bf: A \to Bf:A→B is injective (or one-to-one) if different elements in AAA map to different elements in BBB. In other words, if f(a1)=f(a2)f(a_1) = f(a_2)f(a1​)=f(a2​), then a1=a2a_1 = a_2a1​=a2​.

      • Example: The function f(x)=2xf(x) = 2xf(x)=2x for x∈{1,2,3}x \in \{1, 2, 3\}x∈{1,2,3} is injective because each xxx maps to a unique value in the codomain.
    • Surjective (Onto): A function f:A→Bf: A \to Bf:A→B is surjective (or onto) if every element in BBB is mapped to by at least one element in AAA. In other words, for every b∈Bb \in Bb∈B, there exists at least one a∈Aa \in Aa∈A such that f(a)=bf(a) = bf(a)=b.

      • Example: The function f(x)=x2f(x) = x^2f(x)=x2 for x∈{1,2,3}x \in \{1, 2, 3\}x∈{1,2,3} is surjective if the codomain is {1,4,9}\{1, 4, 9\}{1,4,9}.
    • Bijective (One-to-One and Onto): A function f:A→Bf: A \to Bf:A→B is bijective if it is both injective and surjective. This means each element in AAA maps to a unique element in BBB, and every element in BBB is mapped to by exactly one element in AAA.

      • Example: The function f(x)=x+1f(x) = x + 1f(x)=x+1 for x∈{1,2,3}x \in \{1, 2, 3\}x∈{1,2,3} is bijective if the codomain is {2,3,4}\{2, 3, 4\}{2,3,4}.
    • Identity Function: The identity function on a set AAA, denoted as idAid_AidA​, is a function that maps each element of AAA to itself:

      idA(a)=afor all a∈Aid_A(a) = a \quad \text{for all } a \in AidA​(a)=afor all a∈A
    • Constant Function: A function is constant if all elements in the domain map to the same element in the codomain. For example, f(x)=5f(x) = 5f(x)=5 for all x∈Ax \in Ax∈A is a constant function.

    Function Composition:

    If f:A→Bf: A \to Bf:A→B and g:B→Cg: B \to Cg:B→C are functions, their composition g∘fg \circ fg∘f is defined as:

    (g∘f)(a)=g(f(a))for all a∈A(g \circ f)(a) = g(f(a)) \quad \text{for all } a \in A(g∘f)(a)=g(f(a))for all a∈A

    This means we first apply fff, then apply ggg to the result of fff.


    3. Relations and Functions in Computer Science

    • Databases: Relations are fundamental to relational databases, where tables are used to represent sets, and rows in a table represent ordered pairs (tuples) that show relationships between different data elements.
    • Computer Algorithms: Functions are used extensively in algorithms to define operations such as sorting, searching, and mapping.
    • Programming: Functions are the building blocks of programs, allowing inputs to be mapped to outputs, and are essential for modularity, recursion, and lambda calculus.

    Conclusion

    Relations and functions

    ← Previous topic 11
    Loop Invariants
    Next topic 13 →
    Pigeonhole Principle

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    13mremaining
    2.2kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Discrete Structures