ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Discrete Structures
    CSI-303
    Progress0 / 21 topics
    Topics
    1. Introduction to Logic and Proofs2. Direct Proofs3. Proof by Contradiction4. Sets5. Combinatorics6. Sequences7. Formal Logic8. Propositional and Predicate Calculus9. Methods of Proof10. Mathematical Induction and Recursion11. Loop Invariants12. Relations and Functions13. Pigeonhole Principle14. Trees and Graphs15. Elementary Number Theory16. Optimization and Matching17. Fundamental Structures18. Functions19. Relations (Recursions)20. Cardinality and Countability21. Probabilistic Methods
    CSI-303›Relations and Functions
    Discrete StructuresTopic 12 of 21

    Relations and Functions

    13 minread
    2,212words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time13 min
      Word count2,212
      Code examples0
      DifficultyIntermediate