CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.

Slides:



Advertisements
Similar presentations
CSE 211- Discrete Structures
Advertisements

22C:19 Discrete Structures Advanced Counting Spring 2014 Sukumar Ghosh.
Equivalence Relations
22C:19 Discrete Math Relations Fall 2010 Sukumar Ghosh.
Relations Relations on a Set. Properties of Relations.
5/16/20151 You Never Escape Your… Relations. 5/16/20152Relations If we want to describe a relationship between elements of two sets A and B, we can use.
Applied Discrete Mathematics Week 11: Graphs
Discrete Structures Chapter 5 Relations Nurul Amelina Nasharuddin Multimedia Department.
Relations. Binary Relations a relation between elements of two sets is a subset of their Cartesian product (of ordered pairs). Note the di ff erence between.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
1 Representing Relations Epp section ??? CS 202 Aaron Bloomfield.
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 8: Relations Relations(8.1) n-any Relations &
(CSC 102) Lecture 15 Discrete Structures. Previous Lectures Summary  Procedural Versions  Properties of Sets  Empty Set Properties  Difference Properties.
Chapter Relations and Their Properties 8.2 n-ary Relations and Their Applications 8.3 Representing Relations 8.4 Closures of Relations 8.5 Equivalence.
1 Relations and Their Properties Epp, section ??? CS 202 Aaron Bloomfield.
Module #18: Relations, part I
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a Fall 2002KSU - Discrete Structures1.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Discrete Math for CS Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
CSC-2259 Discrete Structures
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Discrete Structures1 You Never Escape Your… Relations.
1 Relations and Their Properties Rosen, section 7.1 CS/APMA 202 Aaron Bloomfield.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Discrete Mathematics Relation.
Relations and their Properties
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
Lecture on Relations 1Developed by CSE Dept., CIST Bhopal.
1 Partial Orderings Aaron Bloomfield CS 202 Epp, section ???
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Chapter Relations and Their Properties
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
Chap. 7 Relations: The Second Time Around
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
Week 8 - Monday.  What did we talk about last time?  Properties of functions  One-to-one  Onto  Inverses  Cardinality.
1 CMSC 250 Discrete Structures CMSC 250 Lecture 41 May 7, 2008.
Relations and Their Properties
Relations and Their Properties
Introduction to Relations
Learn about relations and their basic properties
Equivalence Relations
Relations Chapter 9.
RELATION KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )
Relations and Their Properties
CSE 504 Discrete Structures & Foundations of Computer Science
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 9 Relations Slides are adopted from.
CMSC Discrete Structures
CS201: Data Structures and Discrete Mathematics I
Discrete Structures for Computer Science
CS2210 Discrete Structures Relations
Discrete Math (2) Haiming Chen Associate Professor, PhD
Applied Discrete Mathematics Week 6: Relations/Digraphs
CSE 321 Discrete Structures
Combining relations via relational composition
Chapter 8 (Part 2): Relations
Presentation transcript:

CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh

What is a relation? Let A, B be two sets. A binary relation R is a subset of A X B. Example. Let A = {Alice, Bob, Claire, Dan) be a set students, and B= {CS101, CS201, CS202) be a set of courses. Then, a possible relation is: {(Alice, CS101), (Bob, CS201), (Bob, CS202), (Dan, CS201), (Dan, CS202)} If |A|= m and |B|= n, then there can be as many 2 mn distinct relations (why?).

What is a relation?

Representing Relations

Relations vs. Functions

When to use which? A function yields a single result for any element in its domain. Example: age (of a person), square (of an integer) etc. A relation allows multiple mappings between the domain and the co-domain. Example: students enrolled in multiple courses.

Relation within a set

Properties of Relations We study six properties of relations: What are these?

Reflexivity Example. = is reflexive, since a = a ≤ is reflexive, since a ≤ a < is not reflexive is a < a is false.

Symmetry

Anti-symmetry

More on symmetric relations

Transitivity

Examples of transitive relations

Summary of properties =<>≤≥ ReflexiveXXX IrreflexiveXX SymmetricX AsymmetricXX AntisymmetricXXX TransitiveXXXXX

Operations on relations Then, R1 ⋃ R2 = {(1,1), (1,2), (1,3), (1,4)} R1 ⋂ R2 = {(1,1), (1,3)} R1 - R2 = {(1,2)} Let A = {1, 2, 3} and B = (1, 2, 3, 4}. Define two relations R1 = {(1,1), (1,2), (1,3)} R2 = {(1,1), (1,3), (1,4)}

More operations on relations: Composition Let S be a relation from the set A to the set B, and R be and R be a relation from the set B to the set C. Then, the composition of S and R, denoted by S ◦ R is { (a, c) | a ∈ A, b ∈ B, c ∈ C such that (a, b) ∈ S and (b, c) ∈ R} EXAMPLE. Let A = {1, 2, 3}, B = { 1, 2, 3, 4}, C = {0, 1, 2} S = {(1,1), (1,4), (2,3), (3, 1), (3, 4)} R = {(1,0), (2,0), (3,1), (3, 2), (4,1) Then S ◦ R = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)

More operations on relations: Composition R n = R n-1 ◦ R = R ◦ R ◦ R ◦ R … (n times) EXAMPLE. Let R = {(1,1), (2,1), (3,2), (4,3)},. Then R 2 = R ◦ R = {(1,1), (2,1), (3, 1), (4,2)} R 3 = R 2 ◦ R = {(1,1), (2,1), (3, 1), (4,1)} R 4 = R 3 ◦ R = {(1,1), (2,1), (3, 1), (4,1)} Notice that in this case for all n > 3, R n = R 3

Transitive Closure The transitive closure of a binary relation R on a set S is the transitive relation R * on S such that EXAMPLE. Let S = {1, 2, 3} and R = {(1,1), (2,1), (3,2), (4,3)}. Then R* = {(1,1), (2,1), (3, 1), (3,2), (4,3), (4,2), (4,1)}

Transitive Closure: A graph view

n-ary relations Has important applications in computer databases. DEFINITION. Let A 1, A 2, A 3, …, A n be n sets. An n-ary relation is a subset of A 1 x A 2 x A 3 x… x A n EXAMPLE. R is a relation on N x N x N consisting of triples (a, b, c) where a < b < c. Thus (1, 2, 3) ∈ R but (3, 6, 2) ∉ R

Relational Data Model NameIDMajorGPA Alice Physics3.67 Bob ECE3.67 Carol ECE3.75 David Computer Science3.25 The above table can be viewed as a 4-ary relation consisting of the 4-tuples (Alice, , Physics, 3.67) (Bob, , ECE, 3.67) (Carol, , ECE, 3.75) (David, , Computer Science, 3.25) Student Record

Relational Data Model NameIDMajorGPA Alice Physics3.67 Bob ECE3.67 Carol ECE3.75 David Computer Science3.25 A domain is called a primary key when no two n-tuples in the relation have the same value from this domain. (These are marked red).

Operations on n-ary relations SELECTION Let R be an n-ary relation, and C be a condition that the elements in R must satisfy. Then the selection operator S C maps the n-ary relation R to the n-ary relations from R that satisfy the condition C. So, from the previous table, one can use a selection operator to filter out the record of all student with GPA > 3.50

Operations on n-ary relations PROJECTION The projection P i,j,k,…,m maps each n-tuple (a 1, a 2, a 3, …, a n ) to the tuple (a i, a j, a k, …, a m ). Essentially it helps you delete some of the components of each n-tuple. Thus, in the table shown earlier, the projection P 1,4 will retain only that part of the table that contains the student names and their GPAs.

Use of the operations on n-ary relations SQL queries SQL queries carry out the operations described earlier: SELECT GPA FROM Student Records WHERE Department = Computer Science

Representing Relations Using Matrices A relation between finite sets can be represented using a 0-1 matrix. Let A = {a 1, a 2, a 3 } and B = {b 1, b 2, b 3 }. A relation R from A to B can be represented by a matrix M R, where m ij = 1 if (a i, b j ) ∈ R, otherwise m ij = 0 a1=1 a2=2 a3=3 b1=1b2=2b3=4 The above denotes a relation R from A = {1,2,3} to B = {1,2,4}, where for each element (a, b) of R, a > b

Representing Relations Using Matrices A reflexive relation on a given set A is recognized by a 1 along the diagonal A symmetric relation A reflexive relation How would the matrix of an anti-symmetric relation look like?

Representing Relations Using Digraph A relation on a given set A can also be represented by a directed graph A directed graph representation of the relation shown on the left Let A = {1, 2, 3}

Equivalence Relations An equivalence relation on a set S is a relation that is reflexive, symmetric and transitive. Examples of equivalence relations are: (1)Congruence relation R = {(a,b) | a = b (mod m)} (2) R = {(a, b) | L(a) = L(b)} in a set of strings of English characters}, L(a) denotes the length of English character string “a”

Equivalence Class Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of a. The equivalence class of a with respect to R is denoted by [a] R. Example 1. What is the equivalence class of 0 for the relation congruence mod 4? [0] mod 4 = [… -8, -4, 0, +4, +8, …] Relations partition the elements of a set into equivalence classes Question. What are the sets in the partition of the integers arising from congruence modulo 4?

Partial Orders A relation R on a set S is a partial order if it is reflexive, anti-symmetric and transitive. The set (S, R) is called a partially ordered set, or a poset. Examples are (1) the ≥ relation, (2) “x divides y” on the set of positive integers (3) The relation ⊆ on the power set of a set S

Hasse Diagram Constructing the Hasse diagram for ({1, 2, 3, 4}, ≤}

More examples Source: The relation ⊆ on the power set of a set S forms a partially ordered set