Relations and Their Properties

Slides:



Advertisements
Similar presentations
CSE 211- Discrete Structures
Advertisements

Chap6 Relations Def 1: Let A and B be sets. A binary relation from A
Basic Properties of Relations
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.
Discrete Mathematics Lecture # 16 Inverse of Relations.
CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.
Ch. 8: Relations 8.1 Relations and their Properties.
Discrete Structures Chapter 5 Relations Nurul Amelina Nasharuddin Multimedia Department.
CSE115/ENGR160 Discrete Mathematics 04/24/12 Ming-Hsuan Yang UC Merced 1.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
Discrete Mathematics Lecture#11.
1 Section 7.1 Relations and their properties. 2 Binary relation A binary relation is a set of ordered pairs that expresses a relationship between elements.
Relations Chapter 9.
Applied Discrete Mathematics Week 10: Equivalence Relations
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 8: Relations Relations(8.1) n-any Relations &
Relation. Relations Recall the definition of the Cartesian (Cross) Product: The Cartesian Product of sets A and B, A x B, is the set A x B = { : x  A.
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.
Lecture 14 Relations CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit Unit 04 Relations IT DisiciplineITD1111 Discrete Mathematics & Statistics STDTLP1 Unit 4 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
Sets Define sets in 2 ways  Enumeration  Set comprehension (predicate on membership), e.g., {n | n  N   k  k  N  n = 10  k  0  n  50} the set.
Discrete Structures1 You Never Escape Your… Relations.
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
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
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.
CS 103 Discrete Structures Lecture 19 Relations. Chapter 9.
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
Discrete Structures – CNS2300
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.
4. Relations and Digraphs Binary Relation Geometric and Algebraic Representation Method Properties Equivalence Relations Operations.
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
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 B = {a,b} {( 0, a), (
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
Section 9.1. Section Summary Relations and Functions Properties of Relations Reflexive Relations Symmetric and Antisymmetric Relations Transitive Relations.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Relations and Their Properties
Relations.
Relations Chapter 9.
Applied Discrete Mathematics Week 10: Relations
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.
Applied Discrete Mathematics Week 9: Equivalence Relations
CMSC Discrete Structures
CS2210 Discrete Structures Relations
Relations and Their Properties
8.1 Relations and Their Properties
CSE15 Discrete Mathematics 04/26/17
Closures of Relations: Transitive Closure and Partitions
Applied Discrete Mathematics Week 5: Boolean Algebra
Applied Discrete Mathematics Week 6: Relations/Digraphs
Relations and their Properties
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Lecture # 16 Inverse of Relations
Presentation transcript:

Relations and Their Properties Sunday, April 23, 2017 Relations and Their Properties Section 8.1 © 2006 by A-H. Esfahanian. All Rights Reserved.

Review: Cartesian Products Sunday, April 23, 2017 Review: Cartesian Products Definition: An ordered n-tuple (a1, a2, …, an) is the ordered collection that has a1 as its first element, a2 as its second element…, and an as its nth element. 2-tuples are called ordered pairs. (a,b) = (c,d) if and only if a=c and b=d (a,b) ≠ (b,a) unless a=b © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Cartesian Product … Definition: The Cartesian product of the sets A1, A2, …, An, denoted A1×A2×… ×An, is the set of ordered n-tuples (a1, a2, …, an), where ai belongs to set Ai for i =1, 2, …, n. A1×A2× …×An = {(a1, a2, …, an) | aiAi for i=1, 2, …, n} © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Binary Relations Definition: Let A and B be sets. A binary relation R from A to B is a subset of the Cartesian product AB. Notation: xRy means (x,y)R, and x is said to be related to y under R. xRy denotes (x,y)R. © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Let A be the set of all cities, and let B be the set of all states in the U.S. Define the relation R from A to B by: (a,b)R if city a is in state b. Some ordered pairs belonging to relation R: R= {(East Lansing, Michigan), (Boulder, Colorado), (Chicago, Illinois), (Columbus, Ohio), …} (East Lansing)R(Michigan), (Boulder)R(Colorado), … © 2006 by A-H. Esfahanian. All Rights Reserved.

Another Example A= {a, b, c, d } B = {1, 2, 3} Sunday, April 23, 2017 Another Example c b d 2 3 1 a A= {a, b, c, d } B = {1, 2, 3} R = {(a,2), (b,1), (b, 2), (c,3), (d,2)}. R 1 2 3 a x b c d Is this relation a function? © 2006 by A-H. Esfahanian. All Rights Reserved.

Functions As Relations Sunday, April 23, 2017 Functions As Relations Recall that: Let f: A → B be a function. The graph of f is the set of ordered pairs Gf = {(x, f (x)) | x  A}. The graph of a function from A to B is a relation from A to B. Conversely, if R is a relation from A to B such that every element in A is the first element of exactly one ordered pair of R, then a function can be defined with R as its graph. © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Relations on a Set Definition: A relation on a set A is a relation from A to A, that is, a subset of AA. Example: Let A = {1, 2, 3, 4}, and R = {(a,b) | a evenly divides b}. What are the elements of R? R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4)} © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example R can be displayed graphically and in tabular form/zero-one matrix form: R 1 2 3 4 1 x x x x 1 1 1 1 2 x x 0 1 0 1 3 x 0 0 1 0 4 x 0 0 0 1 3 2 4 1 © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Relations on a Set… Let A be a set with n elements. How many distinct relations are there on A? Answer: The number of relations is the same as the number of subsets of AA. There are n2 elements in AA. Thus, P(AA), the power set of AA, has 2n2 elements. Therefore, there are 2n2 relations on a set with n elements. © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Types of Relations Definition: A relation R on a set A is called reflexive if (a,a)R for every element a  A, that is, Definition: A relation R on a set A is called irreflexive if (a,a)  R for every element a  A, that is, Note that a relation can be both not reflexive and not irreflexive. © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Consider the following relations on {1,2,3,4}. Which are reflexive, irreflexive, neither? R1 = {(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} Reflexive R2 = {(2,4), (4,2)} Irreflexive R3 = {(1,2), (2,3), (3,4)} R4 = {(1,1), (2,2), (3,3), (4,4)} R5 = {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)} R6 = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} Neither © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Symmetric Relations Definition: A relation R on a set A is called symmetric if (b,a)R whenever (a,b)R for a, b  A, that is, Definition A relation R on a set A is called antisymmetric if whenever (a,b)R and (b,a)R, then a = b, for a, b in A, that is, Note that these definitions are not complementary. Give a relation that is both symmetric and antisymmetric. Give a relation that is neither symmetrick not antisymmetric. A relation can be both Symmetric and antisymmetric. A relation can be neither symmetric nor antisymmetric. © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Consider the following relations on {1,2,3,4}. Which are symmetric, antisymmetric, both, or neither? R1 = {(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} Symmetric R2 = {(2,4), (4,2)} R3 = {(1,2), (2,3), (3,4)} Antisymmetric R4 = {(1,1), (2,2), (3,3), (4,4)} Both R5 = {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)} Neither The “divides” relation on the set of positive integers R6 = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Transitive Relations Definition: A relation R on a set A is called transitive if whenever (a,b)R and (b,c)R, then (a,c)R, for a, b, c in A, that is, Is the “football team relationship” transitive? A defeats B and B defeats C implies A defeats C ? Is the “subclass” relation on classes in an OO program transitive? © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Consider the following relations on {1,2,3,4}. Which are transitive? R1 = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} Transitive R2 = {(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} R3 = {(2,4), (4,2)} Not Transitive R4 = {(1,2), (2,3), (3,4)} R5 = {(1,1), (2,2), (3,3), (4,4)} R6 = {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)} The “divides” relation on the set of positive integers © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Summary Consider the following relations on {1,2,3,4}. Name its properties? R1 = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} T/A R2 = {(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} R/S/T R3 = {(2,4), (4,2)} S R4 = {(1,2), (2,3), (3,4)} A R5 = {(1,1), (2,2), (3,3), (4,4)} R/S/A/T R6 = {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)} None The “divides” relation on the set of positive integers R/A/T Keys: R = Reflexive, S = Symmetric, A = Antisymmetric, T=Transitive © 2006 by A-H. Esfahanian. All Rights Reserved.

Pictorial Representation of Binary Relations on a Finite Set Sunday, April 23, 2017 Pictorial Representation of Binary Relations on a Finite Set Directed Graphs Vertices, one for each element in the set Arcs, one for each ordered-pair in the relation Example: Set S = {1,2,3,4} and relation R on S R = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} 1 4 3 2 © 2006 by A-H. Esfahanian. All Rights Reserved.

Boolean matrix representation of binary relations on a finite set Recall: If R is a binary relation over set S Order the elements of S = { x1, x2, …, xn } Represent by matrix with a 1 in position (i, j) iff xiRxj Example: Set S = {1,2,3,4} and relation R on S R = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} 1

Equivalence Relations Sunday, April 23, 2017 Equivalence Relations A relation R on a set A is called an equivalence relation if it is reflexive, symmetric and transitive. In such a relation, for each element a  A, the set of all elements related to a under R is called the equivalence class of a, and is denoted by [a]. [a] = { (a,b) | a  A  b  A  aRb } © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Example Determine the properties of each of the following relations defined on the set of all real numbers R: R = {(x,y) | x + y = 0} R = {(x,y) | x = y  x = – y} R = {(x,y) | x – y is a rational number} R = {(x,y) | x = 2y} R = {(x,y) | x y ≥ 0} R = {(x,y) | x y = 0} R = {(x,y) | x = 1} R = {(x,y) | x = 1 or y = 1} © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x + y = 0} Solution: Sunday, April 23, 2017 R = {(x,y) | x + y = 0} Solution: It is not reflexive since, for example, (1,1)  R. It is not irreflexive since, for example, (0,0)  R. Since x + y = y + x, it follows that if x + y = 0 then y + x = 0, so the relation is symmetric. It is not antisymmetric since, for example, (–1,1) and (1, –1) are both in R, but 1 ≠ –1 The relation is not transitive since, for example, (1,–1) R and (–1,1) R, but (1,1)  R. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x = y  x = – y} Solution: Sunday, April 23, 2017 R = {(x,y) | x = y  x = – y} Solution: Since for each x, xRx then it is reflexive. Since it is reflexive, it is not irreflexive. Since x = ±y if and only if y = ±x, then it is symmetric. It is not antisymmetric since, for example, (1,–1) and (–1,1) are both in R but 1 ≠ –1 It is also transitive because essentially the product of ±1 and ±1 is ±1. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x – y is a rational number} Sunday, April 23, 2017 R = {(x,y) | x – y is a rational number} Solution: It is reflexive since, for all x, x – x = 0 is a rational number. Since it is reflexive, it is not irreflexive. It is symmetric because, if x – y is rational, then – (x – y) = y – x is also. It is not antisymmetric because, for example, (1, –1) and (– 1,1) are both in R but 1 ≠ –1. It is transitive because if x – y is a rational and y – z is a rational, so is x – y + y – z = x – z. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x = 2y} Solution: Sunday, April 23, 2017 R = {(x,y) | x = 2y} Solution: It is not reflexive since, for example, (1,1)  R. It is not irreflexive since, for example, (0,0)  R. It is not symmetric since, for example, (2,1)  R but (1,2)  R. It is antisymmetric because x = y =0 is the only time that (x,y) and (y,x) are both in R. It is not transitive since, for example, (4,2)  R and (2,1)  R but (4,1)  R. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x y ≥ 0} Solution: It is reflexive since x·x ≥ 0. Sunday, April 23, 2017 R = {(x,y) | x y ≥ 0} Solution: It is reflexive since x·x ≥ 0. Since it is reflexive, it is not irreflexive. It is symmetric as the role of x and y are interchangeable. It is not antisymmetric since, for example, (2,3) and (3,2) are both in R, but 2 ≠ 3. It is not transitive because, for example, (1,0) and (0, – 2) are both in R but (1, – 2) is not. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x y = 0} Solution: It is not reflexive since (1,1)  R. Sunday, April 23, 2017 R = {(x,y) | x y = 0} Solution: It is not reflexive since (1,1)  R. It is not irreflexive since (0,0)  R. It is symmetric as the role of x and y are interchangeable. It is not antisymmetric since, for example, (2,0) and (0,2) are both in R but 2 ≠ 0. It is not transitive because, for example, (1,0) and (0, – 2) are both in R but (1, – 2) is not. © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x = 1} Solution: It is not reflexive since (2,2)  R. Sunday, April 23, 2017 R = {(x,y) | x = 1} Solution: It is not reflexive since (2,2)  R. It is not irreflexive since (1,1)  R. It is not symmetric since, for example, (1,2)  R but (2,1)  R. It is antisymmetric because if (x,y)  R and (y,x)  R it means x = y = 1. It is transitive since if (1,y)  R and (y,z)  R, so is (1,z)  R . © 2006 by A-H. Esfahanian. All Rights Reserved.

R = {(x,y) | x = 1 or y = 1} Solution: Sunday, April 23, 2017 R = {(x,y) | x = 1 or y = 1} Solution: It is not reflexive since (2,2)  R. It is not irreflexive since (1,1)  R. It is symmetric as the roles of x and y are interchangeable. It is not antisymmetric since, for example, (2,1) and (1,2) are both in R but 2 ≠ 1. It is not transitive since, for example, (3,1) and (1,7) are both in R but (3,7)  R . © 2006 by A-H. Esfahanian. All Rights Reserved.

Summary Relation R IR S A T E ✓ R = {(x,y) | x + y = 0} Sunday, April 23, 2017 Summary Relation R IR S A T E R = {(x,y) | x + y = 0} ✓ R = {(x,y) | x = ±y} {(x,y) | x – y is a rational number} R = {(x,y) | x = 2y} R = {(x,y) | x y ≥ 0} R = {(x,y) | x y = 0} R = {(x,y) | x = 1} R = {(x,y) | x = 1 or y = 1} © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Combining Relations Since relations are special kind of sets, all of the operators we used for combining sets could be used to combine relations. © 2006 by A-H. Esfahanian. All Rights Reserved.

Combining Relations – Examples Sunday, April 23, 2017 Combining Relations – Examples Let A={1, 2, 3} and B={1, 2, 3, 4} Let R1 and R2 be relations from A to B R1 = {(1,1), (2,2), (3,3)} R2 = {(1,1), (1,2), (1,3), (1,4)} R1  R2 = {(1,1), (2,2), (3,3), (1,2), (1,3), (1,4)} R1  R2 = {(1,1)} R1  R2 = {(2,2), (3,3)} © 2006 by A-H. Esfahanian. All Rights Reserved.

Composition of Relations Sunday, April 23, 2017 Composition of Relations Definition: Let R be a relation from a set A to a set B, and S be a relation from B to a set C. The composition of R and S, denoted by S o R, is the relation consisting of ordered pairs (a,c), where: aA, cC, and bB | (a,b)R and (b,c)S. A B c R S S o R © 2006 by A-H. Esfahanian. All Rights Reserved.

Example Let A={1, 2, 3}, B={x, y, w, z}, C={0, 1, 2}, Sunday, April 23, 2017 Example Let A={1, 2, 3}, B={x, y, w, z}, C={0, 1, 2}, R a relation from A to B: R = {(1, x), (1, z), (2, w), (3, x), (3, z)}, and S a relation from B to C: S = {(x,0), (y,0), (w,1), (w,2), (z,1)} What is S o R? S o R = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)} © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Powers of Relations Definition: Let R be a relation on the set A. The powers Rn, n = 1, 2, 3,… are defined recursively by: R1 = R, Rn+1=Rn o R, for n  1. So: R2 = RoR, R3 = R2oR = (RoR) o R … © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, April 23, 2017 Rn+1 Rn+1=Rn o R R Rn A A A In the digraph representation, Rn consists of all the order pairs (x,y) where y is reachable from x using a directed path of length n. © 2006 by A-H. Esfahanian. All Rights Reserved.

Example Consider the following relations on {1,2,3,4}. Sunday, April 23, 2017 Example Consider the following relations on {1,2,3,4}. R = {(1,2), (1,3), (3,4)} Is R transitive? No Find R2=R o R R2 = {(1,4)} Consider the following relation: R = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} Is R transitive? Yes R2 = {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} © 2006 by A-H. Esfahanian. All Rights Reserved.

Characterizing Transitive Relations Sunday, April 23, 2017 Characterizing Transitive Relations Theorem: The relation R on a set A is transitive if and only if Rn  R for n = 1, 2, 3, ... If Part: If Rn  R for n = 1, 2, 3, ... then R is transitive See exercise 6.1 Only If Part: If R is transitive then Rn  R for n = 1,2,3, ... Proof By induction Basis: If R is transitive then R1  R (trivially true) Hypothesis: Assume true for n = 1, 2, 3, ... , k Inductive: Given that if R is transitive then Rk  R, we want to show that if R is transitive then Rk+1  R Proof: Assume that R is transitive, and let (a,b) be in Rk+1. So  x  A | (a,x)  R and (x,b)  Rk, by definition of Rk+1. Since R is transitive then Rk  R by inductive hypothesis. So (x,b)  R. Since R is transitive, then (a,b)  R. So Rk+1  R © 2006 by A-H. Esfahanian. All Rights Reserved.

Applications in Relational Databases Section 8.2

Records as n-tuples (with fields) Record is an n-tuple of fields e.g., student record might be 4-tuple of the form: (name, ID#, Major, GPA) Relational Data Base: collection of records e.g. student database { (Anderson, 231455, CSE, 3.88), (Adams, 888323, PHY, 3.45), (Chou, 102147, CSE, 3.49), (Gould, 453876, MTH, 3.45), (Rao, 678543, MTH, 3.90), (Stevens, 786576, PSY, 2.99) } Field associates the attribute (name, ID#, etc.) with a value from a domain (set of student names, set of ID#s, etc.)

Table 1 Student Data: (Student_Name, PID, Major, GPA) Students (ID# is the primary key) Name ID# Major GPA Anderson 231455 CSE 3,88 Adams 888323 PHY 3.45 Chou 102147 3.49 Gould 453876 MTH Rao 678543 3.90 Stevens 786576 PSY 2.99

Operations on relations (tables) Projection : projects a table on one or more attributes (columns) Selection : selects records (rows) that satisfy a condition Join : combines two tables into one based on shared fields Of course, you can also use the “usual” operations on relations (sets) , , –, …

Projection of Students: P1,4 (Students) Columns 1 and 4 are taken from Students Columns 2 and 3 are ignored Name is paired with GPA (perhaps so a department chair can send congratulations or condemnations to students with special GPAs) Beware: the key ID# is lost so there may be some ambiguity Perhaps there were 2 students “Smith”

Projection of Students: P1,4 (Students) Name ID# Major GPA Anderson 231455 CSE 3.88 Adams 888323 PHY 3.45 Chou 102147 3.49 Gould 453876 MTH Rao 678543 3.90 Stevens 786576 PSY 2.99 GPAs Name GPA Anderson 3.88 Adams 3.45 Chou 3.49 Gould Rao 3.90 Stevens 2.99 P1,4

P1,2 (Enrollments) Majors P1,2 Enrollments Name Major Course Glauser BIO MS 475 PY 410 MS 511 Marcus MTH MS 603 Miller CSE MS 575 CS 455 Majors Name Major Glauser BIO Marcus MTH Miller CSE P1,2

Selection: SC Select all records (rows) that satisfy the condition C

SMajor = “CSE” (Enrollments) Name Major Course Glauser BIO MS 475 PY 410 MS 511 Marcus MTH MS 603 Miller CSE MS 575 CS 455 CSE Enrollments Name Major Course Miller CSE MS 575 CS 455 SMajor = “CSE”

SMajor = “CSE”  GPA > 3.5 (Students) Name ID# Major GPA Anderson 231455 CSE 3.88 Adams 888323 PHY 3.45 Chou 102147 3.49 Gould 453876 MTH Rao 678543 3.90 Stevens 786576 PSY 2.99 SMajor = “CSE”  GPA > 3.5 CSE Students on Dean’s list Name ID# Major GPA Anderson 231455 CSE 3.88

Join: Jp (R, S) Joins records (rows) from R and S on the last p fields (columns) of R and the first p fields (columns) of S To join two records corresponding fields must be identical The join of (a1, …, am ) and (b1, …, bn ) is (a1, …, am, bp+1 , …, bn ), if am – p + 1 = b1 and am – p + 2 = b2 and . . . and am = bp

Example: Joining two tables (on 2 cols) … Teaching Assignments Professor Dept. Course No. Cruz ZOO 335 412 Farber PSY 501 617 Grammer PHY 544 551 Rosen CSE 518 MTH 575 Class Schedule Dept. Course No. Room Time CSE 518 N521 2:00 pm MTH 575 N502 3:00 pm 611 4:00 pm PHY 544 B505 PSY 501 A100 617 A110 11:00 am ZOO 335 9:00 am 412 8:00 am

Tables 5 and 6 joined over Dept&Course Tuples of Table 5: cols 2,3 are matched to tuples of Table 6: cols 1, 2. The joined 5-tuples create a new relation The new relation adds (joins) the teacher information to the Class-schedule information the room and time information to the Teaching_assignment information

…yields a new table with 5 columns: Professor Dept. Course No. Room Time Cruz ZOO 335 A100 9:00 am 412 8:00 am Farber PSY 501 3:00 pm 617 A110 11:00 am Grammer PHY 544 B505 4:00 pm Rosen CSE 518 N521 2:00 pm MTH 575 N502 Pure join: Keep only rows that can be joined (inner join)

One useful variation on “pure join”: Professor Dept. Course No. Room Time Cruz ZOO 335 A100 9:00 am 412 8:00 am Farber PSY 501 3:00 pm 617 A110 11:00 am Grammer PHY 544 B505 4:00 pm 551 ? Rosen CSE 518 N521 2:00 pm MTH 575 N502 611 Outer join: keep tuples that don’t join; fill missing entries with special “undefined” value

Table 7 Teaching_schedule Professor Department Course Number Room Time Cruz Zoology 335 A100 9:00 am 412 8:00 am Farber Psychology 501 3:00 pm 617 A110 11:00 am Grammer Physics 544 B505 4:00 pm Rosen Computer science 518 N521 2:00 pm Mathematics 575 N502

SQL: Structured Query Language Query language references Tables and their Attributes and applies conditions to them SELECT Departure_time FROM Flights WHERE Destination = “Detroit” name of Table or relation project P5 (Flights) adds a select condition

Table 8 Flights Flights Airline Flight# Gate Destination Departure Nadir 122 34 Detroit 08:10 Acme 221 22 Denver 08:17 33 Anchorage 08:22 323 Honolulu 08:30 199 13 08:47 222 09:10 322 09:44 SELECT Departure_time FROM Flights WHERE Destination = “Detroit” Result should be: 08:10 08:47 09:44

SQL example SELECT Professor, Time FROM Teaching_assignments, Class_schedule WHERE Department = ‘Mathematics’ project these columns from the join of these tables provided this condition holds The “answer table” is a single 2-tuple: (Rosen, 3:00 pm)