Discrete Structures for Computer Science

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Advanced Counting Spring 2014 Sukumar Ghosh.
Advertisements

22C:19 Discrete Math Relations Fall 2010 Sukumar Ghosh.
Chapter 3 : Relational Model
Relational Algebra Tim Kaddoura CS157A. Introduction  Relational query languages are languages for describing queries on a relational database  Three.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
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.
CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Chapter 11.1 and 11.2 Data Manipulation: Relational Algebra and SQL Brian Cobarrubia Introduction to Database Management Systems October 4, 2007.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 8: Relations Relations(8.1) n-any Relations &
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 1 ©Akhilesh Bajaj, 2000, 2002, 2003, All.
Relational Algebra A presentation for CS 457 By Dawn Haddan.
Discrete Structures1 You Never Escape Your… Relations.
From Relational Algebra to SQL CS 157B Enrique Tang.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
Discrete Mathematics Relation.
Advanced Relational Algebra & SQL (Part1 )
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
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 405G: Introduction to Database Systems Lecture 6: Relational Algebra Instructor: Chen Qian.
N-ary Relations & Their Applications. 2 n-ary Relations Let A 1, A 2, …, A n be sets. An n-ary relation on these sets is a subset of A 1 x A 2 x … x A.
Math 3121 Abstract Algebra I Lecture 6 Midterm back over+Section 7.
IFS180 Intro. to Data Management Chapter 10 - Unions.
CPSC 603 Database Systems Lecturer: Laurie Webster II, Ph.D., P.E.
CSE202 Database Management Systems
Database Systems Chapter 6
Learn about relations and their basic properties
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Applied Discrete Mathematics Week 10: Relations
Relational Algebra Chapter 4 1.
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
CSE 504 Discrete Structures & Foundations of Computer Science
Concept of Aggregation in SQL
Lecture 2 The Relational Model
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Database Management Systems (CS 564)
Database Construction and Usage
SQL: Structured Query Language DML- Queries Lecturer: Dr Pavle Mogin
Relational Algebra Chapter 4, Part A
Introduction to Relational Databases
Chapter 15 QUERY EXECUTION.
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
CS 405G: Introduction to Database Systems
Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud.
Database.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4 1.
The Relational Algebra and Relational Calculus
CS2210 Discrete Structures Relations
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Discrete Math (2) Haiming Chen Associate Professor, PhD
CSPs and Relational DBs
Applied Discrete Mathematics Week 6: Relations/Digraphs
Problem Solving with Constraints
CMPT 354: Database System I
CMPT 354: Database System I
Data Manipulation using Relational Algebra
Lecture 3 Relational Algebra and SQL
CS639: Data Management for Data Science
Lectures 2: Introduction to SQL 1
Problem Solving with Constraints
Problem Solving with Constraints
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Discrete Structures for Computer Science Presented By:Andrew F. Conn Lecture #23: N-ary relations and Representations November 30th, 2016

Announcements This is the end of new material!!! Thank you for sticking it out with me. Please take your OMET evaluations. Also, a huge thanks to Dr. Lee whose material was the basis for this class.

Today n-ary relations Relation Representations Definitions CS application: Relational DBMS Relation Representations Matrix Representation Directed Graphs

We can also “relate” elements of more than two sets Definition: Let 𝐴 1 , 𝐴 2 ,…, 𝐴 𝑛 be sets. An n-ary relation on these sets is a subset of 𝐴 1 × 𝐴 2 ×…×𝐴. The sets 𝐴 1 , 𝐴 2 ,…, 𝐴 𝑛 are called the domains of the relation, and 𝑛 is its degree. Example: Let 𝑅 be the relation on ℤ×ℤ× ℤ + consisting of triples 𝑎, 𝑏, 𝑚 where 𝑎≡𝑏 (𝐦𝐨𝐝 𝑚). What is the degree of this relation? What are the domains of this relation? Are the following tuples in this relation? (8,2,3) (-1,9,5) (11,0,6)

N-ary relations are the basis of relational database management systems Data is stored in relations (a.k.a., tables) Columns of a table represent the attributes of a relation Rows, or records, contain the actual data defining the relation Students Enrollment Name ID Major GPA Stud_ID Course Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 334322 CS 441 Math 336 546346 Math 422 964389 Art 707 Ask about degree, domains

Operations on an RDBMS are formally defined in terms of a relational algebra Relational algebra gives a formal semantics to the operations performed on a database by rigorously defining these operations in terms of manipulations on sets of tuples (i.e., records) Operators in relational algebra include: Selection Projection Rename Join Inner Join Outer join … Aggregation

The selection operator allows us to filter the rows in a table Definition: Let 𝑅 be an n-ary relation and let 𝐶 be a condition that elements in 𝑅 must satisfy. The selection 𝑠 𝑐 maps the n-ary relation 𝑅 to the n-ary relation of all n-tuples from 𝑅 that satisfy the condition 𝐶. Example: Consider the Students relation from earlier in lecture. Let the condition 𝐶1 be Major=“CS” and let 𝐶2 be GPA > 2.5. What is the result of 𝑠 𝐶1 ∧ 𝐶2 (Students)? Answer: (Alice, 334322, CS, 3.45) (Charlie, 045628, CS, 2.75) Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0

The projection operator allows us to consider only a subset of the columns of a table Definition: The projection 𝑃 𝑖 1 , 𝑖 2 ,…, 𝑖 𝑚 maps the n-tuple ( 𝑎 1 , 𝑎 2 , …, 𝑎 𝑛 ) to the m-tuple ( 𝑎 𝑖 1 , 𝑎 𝑖 2 ,…, 𝑎 𝑖 𝑚 ) where 𝑚≤𝑛 Example: What is the result of applying the projection 𝑃 1,3 to the Students table? Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Name Major Alice CS Bob Math Charlie Denise Art

The join operator allows us to create a new table based on data from two or more related tables Definition: Let 𝑅 be a relation of degree 𝑚 and 𝑆 be a relation of degree 𝑛. The Join 𝐽 𝑝 𝑅,𝑆 , where 𝑝≤𝑚 and 𝑝≤𝑛, creates a new relation of degree 𝑚+𝑛−𝑝 containing the subset of 𝑆×𝑅 in which elements from column 𝑝 match. Example: What is the result of the join 𝐽 2 (Students,Enrollments)? Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Enrollment Stud_ID Course 334322 CS 441 Math 336 546346 Math 422 964389 Art 707 NOTE: This syntax different than in book

What is the result of the join 𝐽 2 Students,Enrollments ? Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Enrollment Stud_ID Course 334322 CS 441 Math 336 546346 Math 422 964389 Art 707 𝑝=2 Corresponding Column in 𝑆 Name ID Major GPA Course Alice 334322 CS 3.45 CS 441 Math 336 Bob 546346 Math 3.23 Math 422 Denise 964389 Art 4.0 Art 707

SQL queries correspond to statements in relational algebra Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Name ID Alice 334322 Charlie 045628 SELECT is actually a projection (in this case, 𝑷 𝟏,𝟐 ) SELECT Name, ID FROM Students WHERE Major = “CS” AND GPA > 2.5 The WHERE clause lets us filter (in this case, 𝑺 𝐌𝐚𝐣𝐨𝐫="𝑪𝑺" ∧ 𝑮𝑷𝑨>𝟐.𝟓 )

SQL: An Join Example Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Enrollment Stud_ID Course 334322 CS 441 Math 336 546346 Math 422 964389 Art 707 SELECT Name, ID, Major, GPA, Course FROM Students JOIN Enrollment ON ID = Stud_ID Name ID Major GPA Course Alice 334322 CS 3.45 CS 441 Math 336 Bob 546346 Math 3.23 Math 422 Denise 964389 Art 4.0 Art 707

Group Work! Students Name ID Major GPA Alice 334322 CS 3.45 Bob 546346 Math 3.23 Charlie 045628 2.75 Denise 964389 Art 4.0 Enrollment Stud_ID Course 334322 CS 441 Math 336 546346 Math 422 964389 Art 707 Problem 1: What is 𝑃 1,4 Students ? Problem 2: What relational operators would you use to generate a table containing only the names of Math and CS majors with a GPA > 3.0? Problem 3: Write an SQL statement corresponding to the solution to problem 2. Student/GPA S_{(Major = CS OR Major = Math) AND GPA > 3.0} P_1 Students SELECT Name FROM Students WHERE (Major = CS OR Major = Math) AND GPA > 3.0

Representations of Binary Relations We’ve already learned that Binary Relations can be represented with tables, but let’s formalize that. A Relation between finite sets can be represented as a zero-one matrix. Let 𝑅 be a relation from 𝐴 to 𝐵. Then the matrix that represents 𝑅 is defined by: 𝑚 𝑖,𝑗 = 1, 𝑖𝑓 𝑎 𝑖 , 𝑏 𝑖 ∈𝑅 0, 𝑖𝑓 𝑎 𝑖 , 𝑏 𝑖 ∉𝑅 We label the resulting matrix 𝑀 𝑅 .

Example Relations and Matrices 𝑅 1 = 2,1 , 3,1 , 3,2 𝑀 𝑅 1 = 0 0 1 0 1 1 𝑀 𝑅 2 = 0 1 0 0 0 1 0 1 1 0 1 0 1 0 1 𝑅 2 = 𝑎 1 , 𝑏 2 , 𝑎 2 , 𝑏 1 , 𝑎 2 , 𝑏 3 , 𝑎 2 , 𝑏 4 , 𝑎 3 , 𝑏 1 , 𝑎 3 , 𝑏 3 , 𝑎 3 , 𝑏 5

Final Thoughts Next time: Wrap up and Exam Review! Relations allow us to represent and reason about the relationships between sets in a more general way than functions did Without n-ary relations, DBMS systems would not exist! Do you find this stuff interesting? CS 1555: Introduction to Database Systems CS 1571: Introduction to Artificial Intelligence Next time: Wrap up and Exam Review!