University of Santo Tomas**We aren't endorsed by this school
Course
COMPUTER S 122
Subject
Computer Science
Date
Dec 15, 2024
Pages
18
Uploaded by LieutenantPigeonPerson626
MODULE 5:RELATIONS CS0001 (DISCRETE STRUCTURES 1) 1 subtopic 1:INTRODUCTION TO RELATIONS RELATIONS β’these are derived from a Cartesian productβ’a binary relation π from ?to ?is a set of ordered pairs where first element is from set ?and the second element is from set ?β’e.g., ? = {1, 2}, ? = {?, ?, ?}? Γ ? = {(1, ?), (1, ?), (1, ?), (2, ?), (2, ?), (2, ?)}DOMAIN & RANGE OF A RELATION β’DOMAINothis is defined as the set of all the first elements in the ordered pairβ’RANGEothis is defined as the set of all the second elements in the ordered pairβ’e.g., ? = {1, 2, 3, 5}, ? = {4, 6, 9}oSET BUILDER: π is a relation from set ?to ?such that:π = {(?, ?), difference of ? and ? is odd, ? β ? and ? β ?}oSET ROSTER:π = {(1,4), (1,6), (2,9), (3,4), (3,6), (5,4), (5,6)}βͺDOMAIN: {1, 2, 3, 5}βͺRANGE: {4, 6, 9}
MODULE 5: RELATIONSsubtopic 1: introduction to relationsCS0001 (DISCRETE STRUCTURES 1) 2 EXAMPLE PROBLEM (DOMAIN & RANGE) Find the domain and range of the relation below: β’SET BUILDER:π = {(?, ?) βΆ ? = ? +6?where ? and ? β β and ? < 6}β’to find the elements of the set roster, we have to find the minimum and maximum value for ?which satisfies the condition set in the set builder:othe possible values of ?need to be a natural number and less than 6, but we have to check if all values for ?are also natural numbers:? = {1, 2, 3, 4, 5}π’? ? = ?:? = 1 +61= 7 β βπ’? ? = ?:? = 2 +62= 5 β βπ’? ? = ?:? = 3 +63= 5 β βπ’? ? = ?:? = 4 +64=112β βπ’? ? = ?:? = 5 +65=315β ββ’SET ROSTER: {(1,7), (2,5), (3,5)}oDOMAIN: {?, ?, ?}oRANGE: {?, ?}
MODULE 5: RELATIONSsubtopic 1: introduction to relationsCS0001 (DISCRETE STRUCTURES 1) 3 ARROW DIAGRAM β’e.g., ? = {1, 2, 3, 4, 5}, ? = {2, 3, 4, 5, 6, 7, 8}oSET BUILDER: π is a relation from set ?to ?such that:π = {(?, ?) βΆ ? = ? + 1, β? β ? and ? β ?}oSET ROSTER:π = {(1,2), (2,3), (3,4), (4,5), (5,6)}oARROW DIAGRAM:REPRESENTING RELATIONS USING DIAGRAMS β’DIGRAPHothis is a pictorial representation of a relationoit consists of a set πof VERTICES (or nodes) together with a set πΈof ordered pairs of elements of π, called EDGES (or arcs)β’VERTEXothis is called the initial vertex of edge (?, ?), with ?as the terminating vertexβ’e.g., represent this relation with a digraph:π = {(?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?)}
MODULE 5: RELATIONSsubtopic 1: introduction to relationsCS0001 (DISCRETE STRUCTURES 1) 4 REFLEXIVE, SYMMETRIC, & TRANSITIVE RELATIONS β’a relation on ?is REFLEXIVE if: ?π ?, β? β ?oin laymanβs terms, a relation is reflexive if for all element in set ?, that element is related or maps to itself in relation π βͺnotice how ?, ?, and ?all loop back to itself, denoted by the circular arrowonote that all elements must map to itself, since if there is one element that doesnβt, it cannot be called reflexiveβ’a relation on ?is SYMMETRIC if:β?, ? β ?if ?π ?then ?π ?oa symmetric relation is a binary relation π defined on a set ?for elements ?, ? β ?, we have ?π ?, that is, (?, ?) β π , then we must have ?π ?, that is, (?, ?) β π
MODULE 5: RELATIONSsubtopic 1: introduction to relationsCS0001 (DISCRETE STRUCTURES 1) 5 othis implies that a relation defined on a set A is a symmetric relation if and only if it satisfies ?π ? β ?π ?for all elements ?, ? in ?oif there is a single ordered pair in π such that (?, ?) β π and (?, ?) β π , then π is not a symmetric relation β’a relation is TRANSITIVE if:β?, ?, ? β ?if ?π ?and ?π ?then ?π ?otransitive relations are binary relations defined on a set such that if the first element is related to the second element, and the second element is related to the third element of the set, then the first element must be related to the third elementofor example, if for three elements ?, ?, ? in set ?, if ? = ? and ? = ?, then ? = ?βͺin this example, equality '=' is a transitive relation
MODULE 5: RELATIONSsubtopic 1: introduction to relationsCS0001 (DISCRETE STRUCTURES 1) 6 RELATIONS & THEIR INVERSE β’the inverse relation to π is denoted by π β1and is a subset of ? Γ ?
MODULE 5: RELATIONSsubtopic 2: composition of relationsCS0001 (DISCRETE STRUCTURES 1) 8 EQUIVALENCE OF RELATIONS β’a relation is said to be an equivalence relation if it is reflexive, symmetric, and transitiveβ’REFLEXIVEoβ? β ?, (?, ?) β π oe.g., ? = {1, 2, 3}βͺ(1,1) β π βͺ(2,2) β π βͺ(3,3) β π β’NOT REFLEXIVEoβ? β ?, (?, ?) β π β’SYMMETRICo?, ? β ?, (?, ?) β π , (?, ?) β π oe.g., ? = {1, 2, 3}βͺπ = {(1,2), (2,1)}β’NOT SYMMETRICoβ?, ? β ?, (?, ?) β π , (?, ?) β π β’TRANSITIVEo?, ?, ? β ?, (?, ?) β π , (?, ?) β π , (?, ?) β π oe.g., ? = {1, 2, 3}βͺπ = {(1,2), (2,3), (1,3)}β’NOT TRANSITIVEoβ?, ?, ? β ?, (?, ?) β π , (?, ?) β π , (?, ?) β π EXAMPLE PROBLEM (EQUIVALENCE OF RELATIONS) Check if the following relation is an equivalence relation: πΉ = {(?, ?) βΆ ? π’π¬ ?π’π―π’π¬π’ππ₯? ππ² ?, ?, ? β π΅}β’SOLUTION:ofirst, check its REFLEXIVITY:βͺsince any natural number is divisible by itself, this relation is reflexiveβͺe.g., 3is divisible by 3,and so on
MODULE 5: RELATIONSsubtopic 2: composition of relationsCS0001 (DISCRETE STRUCTURES 1) 9 onext, check its SYMMETRY:βͺletβs say we have ? = 3and ? = 6βͺalthough we can say that 6is divisible by 3, we cannot say the same for the other way around (that is, 3is not divisible by 6) βͺtherefore, it is NOT symmetricalosince it does not meet the second condition, there is no need to check its TRANSITIVITY, and we can already conclude that it is NOT an equivalence relationπ-ARY RELATIONS β’a BINARY relation involves two sets and can be described by a set of pairsβ’a TERNARY relation involves three sets and can be described by a set of triplesβ’an π-ary relation involves πsets and can be described by a set of π-tuplesoan π-ary relation is a relation between ANY number of values
MODULE 6:FUNCTIONS CS0001 (DISCRETE STRUCTURES 1) 10 subtopic 1:INTRODUCTION TO FUNCTIONS FUNCTIONS β’a function is a connection between two sets ?and ?such that all elements in ?are associated to some elements in ?oNOTE: this association is uniqueβ’e.g., ?: ? β ?(that is, ?(?) = ?or (?, ?) β ?)? = {1, 2, 3, 4}? = {1, 5, 9, 11, 15, 16}o?1= {(1,1), (2,11), (3,1), (4,15)}βͺsince there are no repeating values for the ?values and all values exist in either set, it is a FUNCTIONo?2= {(1,1), (2,7), (3,5)}βͺsince 7is a ?value even though it does not exist in ?, this is NOT a functiono?3= {(1,5), (2,9), (3,1), (4,5), (2,11)}βͺsince the ?value 2repeats, even though all elements exist in either set, this is still NOT a functionDOMAIN OF A FUNCTION β’this is the INPUT, or the INSIDE of the function ?(?)β’in ?(?), it is composed of all values of ?for which ?(?)is definedβ’e.g., ?(?) = ?3β 3onote that you can plug in any value for ?, as long as ? β βotherefore, βbecomes the DOMAIN for the given function
MODULE 6: FUNCTIONSsubtopic 1: introduction to functionsCS0001 (DISCRETE STRUCTURES 1) 11 β’how can we ensure that our function stays defined or gives a valid answer/output?ofirst, ensure that the denominator of a function can never be 0othen, check if the expression inside the square root β (or any root with even index) evaluates to β₯ 0(zero or positive)EXAMPLE PROBLEM (DOMAIN OF A FUNCTION) Find the domain of the function below: ?(?) =??+ ?? + ???β ?? + ??β’SOLUTIONofirst, split the denominator into linear factors and equate it to zero (because the denominator cannot be zero)?2β 8? + 12 β 0(? β 6)(? β 2) β 0? β 6 β 0? β 6? β 2 β 0? β 2otherefore, the domain must be every real number except 6and 2βͺthat is, DOMAIN: β β {2, 6}RANGE OF A FUNCTION β’to find the range of a function, follow these steps:oSTEP 1: put ? = ?(?)oSTEP 2: express ?as the function of ?oSTEP 3: find the possible values of ?
MODULE 6: FUNCTIONSsubtopic 1: introduction to functionsCS0001 (DISCRETE STRUCTURES 1) 12 oSTEP 4: eliminate values by looking at the definition to write the rangeβ’the range of a function is the set of all possible values that the function can output given its domainEXAMPLE PROBLEM (RANGE OF A FUNCTION) Find the range of the function below: ?(?) =? β ?? β ?β’SOLUTION:ofirst, equate the function to ?? β 23 β ?= ?othen, express ?as the function of ?by isolating the ?variable (start by cross-multiplying in this case)? β 2 = ?(3 β ?)? β 2 = 3? β ??? + ?? = 3? + 2?(1 + ?) = 3? + 2? =?? + ?? + ?onow, find the values of ?that would make the denominator zero (hence, excluding it from the range set) by equating it to 0
MODULE 6: FUNCTIONSsubtopic 1: introduction to functionsCS0001 (DISCRETE STRUCTURES 1) 13 1 + ? β 0? β β1otherefore, the range is the set of real numbers except ? = β1βͺthat is, RANGE: β β {β1}INJECTIVE (ONE-TO-ONE) FUNCTIONS β’these are functions where each value in the range corresponds to exactly one element in the domainβ’that is, β?β? ((? β ?) β (?(?) β ?(?)))SURJECTIVE (ONTO) FUNCTIONS β’these are functions where every element in the codomain (range) maps to at least one element in the domainβ’that is, β?β? = (?(?) = ?)
MODULE 6: FUNCTIONSsubtopic 1: introduction to functionsCS0001 (DISCRETE STRUCTURES 1) 14 BIJECTIVE FUNCTIONS β’these are functions that are both INJECTIVE and SURJECTIVEβ’e.g.,
MODULE 6: FUNCTIONSsubtopic 2: composition of functionsCS0001 (DISCRETE STRUCTURES 1) 15 subtopic 2:COMPOSITION OF FUNCTIONS FUNCTION OPERATIONS β’say you have these two functions ?and ?:?(?) = 2? + 5?(?) = ?2β 4β’ADDITION:(? + ?)(?) = (2? + 5) + (?2β 4)(? + ?)(?) = ??+ ?? + ?β’SUBTRACTION: (? β ?)(?) = (2? + 5) β (?2β 4)(? β ?)(?) = (2? + 5) β ?2+ 4(? β ?)(?) = β??+ ?? + ?β’MULTIPLICATION:(? β ?)(?) = (2? + 5)(?2β 4)(? β ?)(?) = ???+ ???β ?? β ??β’NOTE: the domain of the functions formed by these first three operations are ALL REAL NUMBERS ββ’DIVISION: (??)(?) =2? + 5?2β 4β’however, for division, the domain is:
MODULE 6: FUNCTIONSsubtopic 2: composition of functionsCS0001 (DISCRETE STRUCTURES 1) 16 ?2β 4 β 0(? + 2)(? β 2) β 0? + 2 β 0? β β2? β 2 β 0? β 2othe DOMAIN of ?/? would be all real numbers except Β±2βͺthat is, DOMAIN: β β {β2, 2}COMPOSITION OF TWO FUNCTIONS β’this is when a function is substituted as βinputβ to another functionβ’e.g.,?(?) = ? + 3?(?) = ?2β 5o(? β ?)(?)(? β ?)(?) = ?(?(?)) = (?2β 5) + 3(? β ?)(?) = ??β ?o(? β ?)(?)(? β ?)(?) = ?(?(?)) = (? + 3)2β 5(? β ?)(?) = ?(?(?)) = (?2+ 6? + 9) β 5(? β ?)(?) = ??+ ?? + ?
MODULE 6: FUNCTIONSsubtopic 2: composition of functionsCS0001 (DISCRETE STRUCTURES 1) 17 GRAPHING A BASIC FUNCTION β’e.g., graph the function ?(?) = 5? β 4
MODULE 6: FUNCTIONSsubtopic 2: composition of functionsCS0001 (DISCRETE STRUCTURES 1) 18 INVERSE OF A FUNCTION β’this is when you swap the ?and ?variable of the function and then solve for ?by isolating itβ’e.g., find the inverse of ?(?) = 2? β 7? = 2? β 7? = 2? β 7? + 7 = 2?? + 72= ?otherefore, the inverse function of ?(?) is:?β?(?) =? + ??β’e.g., find the inverse of ?(?) = ?3+ 8? = ?3+ 8? = ?3+ 8? β 8 = ?3β? β 83= ?otherefore, the inverse function of ?(?)is:?β?(?) = β? β ??