CS1022 Computer Programming & Principles

Slides:



Advertisements
Similar presentations
Partial Orderings Section 8.6.
Advertisements

Section 7.5: Equivalence Relations Def: A relation R on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive. Ex: Let.
Relations Relations on a Set. Properties of Relations.
CS1022 Computer Programming & Principles Lecture 2 Relations.
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Instructor: Hayk Melikya
Partially Ordered Sets (POSets)
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
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.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
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)
Lecture 4.4: Equivalence Classes and Partially Ordered Sets CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda.
Discrete Mathematics Relation.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Relations and their Properties
Copyright © Cengage Learning. All rights reserved.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Chapter SETS DEFINITION OF SET METHODS FOR SPECIFYING SET SUBSETS VENN DIAGRAM SET IDENTITIES SET OPERATIONS.
Mathematical Preliminaries
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
1 Partial Orderings Aaron Bloomfield CS 202 Epp, section ???
DISCRETE COMPUTATIONAL STRUCTURES
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 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.
MAT 2720 Discrete Mathematics Section 3.3 Relations
Lecture 5 Set Theory. Plan of lecture Why set theory? Sets and their properties Membership and definition of sets “Famous” sets Types of variables and.
1 Partial Orderings Epp, section Introduction An equivalence relation is a relation that is reflexive, symmetric, and transitive A partial ordering.
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 is a relation on.
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
Chapter 5 Relations and Operations
Lecture 6 Set Theory.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
The Language of Sets If S is a set, then
CSNB 143 Discrete Mathematical Structures
Unit-III Algebraic Structures
Partial Orderings CSE 2813 Discrete Structures.
Introduction to Relations
Relations Binary relations represent relationships between the elements of two sets. A binary relation R from set A to set B is defined by: R  A 
Equivalence Relations
Relations Chapter 9.
CS1022 Computer Programming & Principles
Chapter 2: Intro to Relational Model
Aaron Bloomfield CS 202 Epp, section ???
CSE 504 Discrete Structures & Foundations of Computer Science
CS1022 Computer Programming & Principles
CSNB 143 Discrete Mathematical Structures
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 9 Relations Slides are adopted from.
CS201: Data Structures and Discrete Mathematics I
Chapter 2 Sets and Functions.
Set Theory A B C.
Set Operations Section 2.2.
CS2210 Discrete Structures Relations
Applied Discrete Mathematics Week 6: Relations/Digraphs
Advanced Algorithms Analysis and Design
Chapter 2: Intro to Relational Model
Relations.
Lecture Sets 2.2 Set Operations.
Foundations of Discrete Mathematics
Chapter 8 (Part 2): Relations
Section 3.2 More set operations.
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 2 Relations

Plan of lecture Equivalence relations Set partition Partial order Total order Database management systems CS1022

Equivalence relation A relation R on A which is Reflexive (x  A  (x, x)  R), Symmetric ((x, y)  R)  ((y, x)  R)), and Transitive (((x, y)  R and (y, z)  R)  (x, z)  R) is called an equivalence relation Equivalence relation generalises/abstracts equality Pairs share some common features Example: Relation “has same age” on a set of people – related people belong to “same age sub-group” Natural way to split up elements (partition) CS1022

Set partition (1) Underlying set A of equivalence relation R can be split into disjoint (no intersection) sub-sets Elements of subsets are all related and equivalent to each other “Equivalent” is well-defined (and can be checked) Very important concept Underpins classification systems CS1022

Set partition (2) A partition of a set A is a collection of non-empty subsets A1, A2, , An, such that A  A1  A2    An i, j, 1  i  n, 1  j  n, i  j, Ai  Aj   Subsets Ai, 1  i  n, are blocks of the partition Sample Venn diagram: 5 blocks A Blocks do not overlap Their intersection is empty A1 A2 A3 A4 A5 CS1022

Set partition (3) Subsets/partitions consist of related elements of A Equivalence class Ey, of any y  A, is the set Ey  z  A : z R y Theorem: Let R be an equivalence relation on a non-empty set A The distinct equivalence classes form a partition of A Proof in 4 parts: Show that equivalent classes are non-empty subsets of A Show that if x R y then Ex  Ey Show that A  Ex1  Ex2    Exn Show that for any two Ex and Ey, Ex  Ey   Ey is the set of things that are in the equivalence class with respect to y. See later. CS1022

Set partition (4) Example: relation R on R (real numbers) defined as x R y if and only if x  y is an integer (Z). x  y is an integer is an equivalence relation. (x  y)  Z Proof: Since x  x  0 for any real number x, then R is reflexive If x  y is an integer then y  x  (x  y) is the negative of an integer, which is an integer, hence R is symmetric If x  y and y  z are integers then x  z  (x  y) + (y  z) is the sum of two integers, which is another integer, so R is transitive Therefore R is an equivalence relation Uses a bit of number theory. Examples: 7-5 = -(5-7); (7-5)+(5-2) = (7-2). CS1022

Set partition (5) Our previous example is y  R, Ey  z  R : (z  y)  Z We can obtain the following equivalence classes: E0  z  R : (z  0)  Z  Z (all integers) E½  z  R : (z  ½)  Z  , 1½, ½, ½, 1½, 2½,  E2 z  R : (z  2)  Z  , 1  2, 2, 1  2, 2  2,  How would it work if we have a set of ordered pairs of names and ages, e.g. {(Jill, 35), (Bill, 37), (Phil, 35) (Mary, 35) (Will, 37)}, and the relation is 'same age as'? R is the set of reals. Z is the set of integers. CS1022

Partial order (1) "is taller than" a partial order? A relation R on A which is Reflexive (x  A  (x, x)  R), Anti-symmetric ((x, y)  R) and (x  y))  ((y, x)  R)), and Transitive (((x, y)  R and (y, z)  R)  (x, z)  R) Is a partial order Sets on which partial order is defined are “posets” Partial orders help us defining precedence Decide when an element precedes another Establish an order among elements Sample partial orders “” on the set R of real numbers “” on subsets of some universe set "is taller than" a partial order? CS1022

Partial order (2) If R is a partial order on A and x R y, x  y, we call x a predecessor of y y a successor of x An element may have many predecessors If x is a predecessor of y and there is no z, x R z and z R y, then x is an immediate predecessor of y We represent this as x  y CS1022

Partial order (3) Immediate predecessors graphically represented as a Hasse diagram: Vertices are elements of poset A If x  y, vertex x is placed below y and joined by edge A Hasse diagram has complete information about original partial order Provided we infer which elements are predecessors of others, by working our way upwards on chain of edges CS1022

Partial order (4) Example: relation “is a divisor of” on set Defines a partial order Table of predecessors & immediate predecessors element predecessors immediate 1 none 2 3 6 1, 2, 3 2, 3 12 1, 2, 3, 6 18 6 12 18 3 2 1 Why the branch? CS1022

Total order A total order on a set A is a partial ordering in which every pair of elements are related. The Hasse diagram of a total order is a long chain Examples of total orders: Relation “” on Real numbers Lexicographical ordering of words in a dictionary In computing: Sorting algorithms require total ordering of elements Posets with minimal/maximal elements useful too CS1022

Database management systems (1) Data with lifespan Data stored in variables only exist while program runs Data shown on screen only exist while being shown Some data must be persistent It should be kept for hours, days, months or even years Simple way to make data persistent: files Data saved electronically on your hard-disk Records (lines) contain numbers, strings, etc. A “flat file” (e.g. a lexicon) allows sequential processing of records: To access line/record n, we must read previous n1 lines CS1022

Database management systems (2) Alternative to “flat files”: databases Databases allow efficient access to records We can directly access record n We can search for records which meet some criteria Database management system (DBMS) Means to create and manage databases (notice plural) Infra-structure to organise/store data, records Means to access/query records No need to create our own database systems Existing solutions – stable technology, free, efficient, scale up MySQL (www.mysql.com) Trend: databases in the “cloud” (Amazon) CS1022

Database management systems (3) Data in DB must be thought out Only data needed should be there Same data should not appear in two (or more) places If data can be obtained from other data, then it should not be stored (e.g., unit price and total batch price) Challenge of database design/management Selecting the “right” data Organising data (what should go with what and where) Deciding when to re-design databases (due to problems) CS1022

Tables (1) Data in DB stored as tables Table T1: Personal details (student record system) ID No. Name Sex DOB Marital Status Address 4000123 Jones Female 1.2.83 Single 2 The Motte, Newton 5001476 Singh Male 4.5.84 Married 4A New Road, Seaforth 5112391 Smith 21.3.84 17 The Crescent, Seaforth 5072411 12.12.84 21 Pudding Lane, Witham 5532289 Ching 15.8.83 5083001 Grant 9.7.83 18 Iffley Road, Reading 5196236 McKay 133 Uff Road, Reading 4936201 French 7.10.77 11 Finn Road, Newtown ID. Numbers should be unique Names can be repeated (e.g., Smith) Problems when listing students just by name CS1022

Tables (2) A table with n columns A1, A2, , An is a subset of the Cartesian product A1  A2    An All records should be members of the product CS1022

Names  Marks  Marks  Marks  Marks Tables (3) Table T2: Course results Name Intro to Maths Programming Discrete Maths Computer Systems Cummings A B C Jones D Grant Singh French E McKay Cookson Table is Cartesian product of Names  Marks  Marks  Marks  Marks Rows are elements (Jones, B, C, B, D) (Grant, C, B, A, C) CS1022

Database operations DBMS provides operations on tables to Extract information Modify tables Combine tables Some of these operations are Project (as in "to project") Join Select CS1022

Project operation Selects columns of a table to form a new table T3 = project(T1,{Name, Address}) yields Name Address Jones 2 The Motte, Newton Singh 4A New Road, Seaforth Smith 17 The Crescent, Seaforth 21 Pudding Lane, Witham Ching Grant 18 Iffley Road, Reading McKay 133 Uff Road, Reading French 11 Finn Road, Newtown CS1022

Join operation Takes two tables and joins their information Puts together tuples which agree on attributes join(T3, T2) yields Name Address Intro to Maths Programming Discrete Maths Computer Systems Jones 2 The Motte, Newton B C D Grant 18 Iffley Road, Reading A Singh 4A New Road, Seaforth French 11 Finn Road, Newtown E McKay 133 Uff Road, Reading CS1022

Select operation Extracts rows of a table which satisfy criteria select(T1, (Sex = Male and Marital Status = Married)) ID No. Name Sex DOB Marital Status Address 5001476 Singh Male 4.5.84 Married 4A New Road, Seaforth 5083001 Grant 9.7.83 18 Iffley Road, Reading Contrast with T5 = {(I,N,S,D,M,A) : (I,N,S,D,M,A)  T1 and S = Male and M = Married} CS1022

Summary You should now know: What equivalence relations are Definition of set partition Partial and total order of a relation Concepts of database management systems CS1022

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 4) CS1022