CS1022 Computer Programming & Principles

Slides:



Advertisements
Similar presentations
Sets of Real Numbers The language of set notation.
Advertisements

22 March 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Introduction.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Instructor: Hayk Melikya
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Sets DISCRETE STRUCTURE ABDUL BASIT TAHIR, KAMRAN ALI, FAIZAN ILLAHI, NOMAN AHMAD, ARSALAN MUBASHIR.
Analytical Methods in CS (CIS 505)
Discrete Structures Chapter 3 Set Theory Nurul Amelina Nasharuddin Multimedia Department.
Chapter 2 The Basic Concepts of Set Theory
Sets 1.
Sets 1.
Chapter 2 The Basic Concepts of Set Theory © 2008 Pearson Addison-Wesley. All rights reserved.
1 Learning Objectives for Section 7.2 Sets After today’s lesson, you should be able to Identify and use set properties and set notation. Perform set operations.
Set Notation.
This section will discuss the symbolism and concepts of set theory
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
Discrete Structure Sets. 2 Set Theory Set: Collection of objects (“elements”) a  A “a is an element of A” “a is a member of A” a  A “a is not an element.
Mathematical Proofs. Chapter 1 Sets 1.1 Describing a Set 1.2 Subsets 1.3 Set Operations 1.4 Indexed Collections of Sets 1.5 Partitions of Sets.
CS201: Data Structures and Discrete Mathematics I
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (1)
CompSci 102 Discrete Math for Computer Science
Chapter 2 Section 1 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Copyright © Cengage Learning. All rights reserved.
Section 2.1. Section Summary Definition of sets Describing Sets Roster Method Set-Builder Notation Some Important Sets in Mathematics Empty Set and Universal.
Naïve Set Theory. Basic Definitions Naïve set theory is the non-axiomatic treatment of set theory. In the axiomatic treatment, which we will only allude.
1 Introduction to Abstract Mathematics Sets Section 2.1 Basic Notions of Sets Section 2.2 Operations with sets Section 2.3 Indexed Sets Instructor: Hayk.
Chapter SETS DEFINITION OF SET METHODS FOR SPECIFYING SET SUBSETS VENN DIAGRAM SET IDENTITIES SET OPERATIONS.
Module Code MA1032N: Logic Lecture for Week Autumn.
Chapter 2 With Question/Answer Animations. Section 2.1.
Rosen 1.6, 1.7. Basic Definitions Set - Collection of objects, usually denoted by capital letter Member, element - Object in a set, usually denoted by.
1 Chapter Two Basic Concepts of Set Theory –Symbols and Terminology –Venn Diagrams and Subsets.
Discrete Mathematics Lecture # 10. Set Theory  A well defined collection of {distinct} objects is called a set.  The objects are called the elements.
Basic Definitions of Set Theory Lecture 24 Section 5.1 Fri, Mar 2, 2007.
Discrete Mathematics Set.
Notions & Notations (2) - 1ICOM 4075 (Spring 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Spring.
Discrete Mathematics CS 2610 August 31, Agenda Set Theory Set Builder Notation Universal Set Power Set and Cardinality Set Operations Set Identities.
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.
The Basic Concepts of Set Theory. Chapter 1 Set Operations and Cartesian Products.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Introduction to Set Theory (§1.6) A set is a new type of structure, representing an unordered collection (group, plurality) of zero or more distinct (different)
Section 6.1 Set and Set Operations. Set: A set is a collection of objects/elements. Ex. A = {w, a, r, d} Sets are often named with capital letters. Order.
Lecture 6 Set Theory.
Dr. Ameria Eldosoky Discrete mathematics
1.1 Subsets of Real Numbers
Chapter 2 Sets and Functions.
CHAPTER 2 Set Theory A B C.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
CSNB 143 Discrete Mathematical Structures
Lecture 04 Set Theory Profs. Koike and Yukita
CS1022 Computer Programming & Principles
The Basic Concepts of Set Theory
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Intro to Set Theory The Math of Santa’s Bag.
CS100: Discrete structures
Set and Set Operations Grab a sheet from front.
Set Operations Section 2.2.
        { } Sets and Venn Diagrams Prime Numbers Even Numbers
Algebra 1 Section 1.1.
The Basic Concepts of Set Theory
CHAPTER 1 - Sets and Intervals
Chapter 2 The Basic Concepts of Set Theory
Applied Discrete Mathematics Week 2: Proofs
CHAPTER 1 - Sets and Intervals
Discrete Mathematics CS 2610
Chapter 2 The Basic Concepts of Set Theory
Chapter 7 Logic, Sets, and Counting
Thinking Mathematically
Thinking Mathematically
Introduction A set is a collection of objects.
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 1 Set Theory

Plan of lecture Why set theory? Sets and their properties Membership and definition of sets “Famous” sets Types of variables and sets Sets and subsets Venn diagrams Set operations CS1022

Why set theory? Set theory is a cornerstone of mathematics Provides a convenient notation for many concepts in computing such as lists, arrays, etc. and how to process these CS1022

Sets A set is A collection of objects Separated by a comma Enclosed in {...} (curly brackets) Examples: {Edinburgh, Perth, Dundee, Aberdeen, Glasgow} {2, 3, 11, 7, 0} {CS1024, CS1022, CS1019, SX1009} Each object in a set is called an element of the set We use italic capital letters to refer to sets: C = {2, 3, 11} is the set C containing elements 2, 3 and 11 CS1022

Sets – indices Talk about arbitrary elements, where each subscript is a different integer: {ai, aj, ..., an} Talk about systematically going through the set, where each superscript is a different integer: {a1i, a2j, ..., a7n} {Edinburgh1, Perth2, Dundee3, Aberdeen4, Glasgow5} CS1022

Properties of sets The order of elements is irrelevant {1, 2, 3} = {3, 2, 1} = {1, 3, 2} = {2, 3, 1} There are no repeated elements {1, 2, 2, 1, 3, 3} = {1, 2, 3} Sets may have an infinite number of elements {1, 2, 3, 4, ...} (the “...” means it goes on and on...) What about {0, 4, 3, 2, ...}? CS1022

Membership and definition of sets Membership of a set a  S – represents that a is an element of set S a  S – represents that a is not an element of set S For large sets we can use a property (a predicate!) to define its members: S = {x : P(x)} – S contains those values for x which satisfy property P N = { x : x is an odd positive integer} = {1, 3, 5, ...} CS1022

Why set theory? Example: check if an element occurs in a collection begin input x, a14, a22, ...,a87; found := false; for i := 1 to n do if x = aij then found := true and output found; else output found; end search though collection by superscript. begin input x, a1, a2, ...,an; if x  {a1, a2, ...,an} then found := true; end CS1022

Names of “famous” sets Some sets have a special name and symbol: Empty set: has no element, represented as { } or  Natural numbers: N = {1, 2, 3, ...} Integers: Z = {..., -3, -2, -1, 0, 1, 2, 3, ...} Rational numbers: Q = {p/q : p, q  Z, q  0} Real numbers: R = {all decimals} N.B.: in some texts/books 0  N CS1022

Types (of variables) and sets Many modern programming languages require that variables be declared as belonging to a data type A data type is a set with a selection of operations on that set Example: type “int” in Java has operations +, *, div, etc. When we declare the type of a variable we state what set the value of the variable belongs to and the operations that can be applied to it. CS1022

A  B if, and only if, x ((x  A) (x  B)) Sets and subsets Some sets are contained in other sets {1, 2, 3} is contained in {1, 2, 3, 4, 5} N (natural numbers) is contained in Z (integers) Set A is a subset of set B if every element of A is in B We represent this as A  B Formally, A  B if, and only if, x ((x  A) (x  B)) CS1022

Venn diagrams A diagram to represent sets and how they relate A set is represented as an oval, a circle or rectangle With or without elements in them Venn diagrams show area of interest in grey Venn diagram showing a set and a subset A 1 2 3 472 B John Venn C D D  C CS1022

x ((x  A) (x  B)) and y ((y  B) (y  A)) Set equality (1) Two sets are equal if they have the same elements Formally, A and B are equal if A  B and B  A That is, x ((x  A) (x  B)) and y ((y  B) (y  A)) We represent this as A = B CS1022

Set equality (2) Let A = {n : n2 is an odd integer} Let B = {n : n is an odd integer} Show that A = B Solution If x  A then x2 is an odd integer, which means x is odd (this needs a proof, but let’s assume it has been proven). Therefore, x  B and so A  B. Conversely, if x  B then x is an odd integer, and x2 is an odd integer (this also needs a proof, but again let’s assume it has been proven). Therefore, x  A and so B  A. Solution Solution If x  A then x2 is an odd integer, which means x is odd (this needs a proof, but let’s assume it has been proven). Therefore, x  B and so A  B. CS1022

Set equality (3) Proof has two parts Part 1: all elements of A are elements of B Part 2: all elements of B are elements of A CS1022

Set operations: union (1) The union of sets A and B is A  B = {x : x  A or x  B} That is, Those elements belonging to A together with Those elements belonging to B and (Possibly) those elements belonging to both A and B N.B.: no repeated elements in sets!! Examples: {1, 2, 3, 4}  {4, 3, 2, 1} = {1, 2, 3, 4} {a, b, c}  {1, 2} = {a, 1, b, 2, c} CS1022

Set operations: union (2) Venn diagram (area of interest in grey) A B A  B CS1022

Set operations: intersection (1) The intersection of sets A and B is A  B = {x : x  A and x  B} That is, Only those elements belonging to both A and B Examples: {1, 2, 3, 4}  {4, 3, 2, 1} = {1, 2, 3, 4} {a, b, c}  {1, 2} = { } =  (empty set) CS1022

Set operations: intersection (2) Venn diagram (area of intersection in darker grey) A B A  B CS1022

Set operations: complement (1) The complement of a set B relative to a set A is A – B = A \ B = {x : x  A and x  B} That is, Those elements belonging to A and not belonging to B Examples: {1, 2, 3, 4} – {4, 3, 2, 1} = { } =  (empty set) {a, b, c} – {1, 2} = {a, b, c} {1, 2, 3} – {1, 2} = {3} CS1022

Set operations: complement (2) Venn diagram (area of interest in darker grey) A B A – B CS1022

Universal set Sometimes we deal with subsets of a large set U U is the universal set for a problem In our previous Venn diagrams, the outer rectangle is the universal set Suppose A is a subset of the universal set U Its complement relative to U is U – A We represent as U – A = A = {x : x  A} A CS1022

Set operations: Symmetric difference Symmetric difference of two sets A and B is A  B = {x : (x  A and x  B) or (x  B and x  A)} That is: Elements in A and not in B or Elements in B and not in A Or: elements in A or B, but not in both (grey area) A B CS1022

Examples Let A = {1, 3, 5, 7} B = {2, 4, 6, 8} C = {1, 2, 3, 4, 5} Find A  C B  C A – C B  C CS1022

Examples Let A = {1, 3, 5, 7} B = {2, 4, 6, 8} C = {1, 2, 3, 4, 5} Find A  C = {1, 3, 5, 7}  {1, 2, 3, 4, 5} = {1, 2, 3, 4, 5, 7} B  C A – C B  C CS1022

Examples Let A = {1, 3, 5, 7} B = {2, 4, 6, 8} C = {1, 2, 3, 4, 5} Find A  C = {1, 3, 5, 7}  {1, 2, 3, 4, 5} = {1, 2, 3, 4, 5, 7} B  C = {2, 4, 6, 8}  {1, 2, 3, 4, 5} = {2, 4} A – C B  C CS1022

Examples Let A = {1, 3, 5, 7} B = {2, 4, 6, 8} C = {1, 2, 3, 4, 5} Find A  C = {1, 3, 5, 7}  {1, 2, 3, 4, 5} = {1, 2, 3, 4, 5, 7} B  C = {2, 4, 6, 8}  {1, 2, 3, 4, 5} = {2, 4} A – C = {1, 3, 5, 7} – {1, 2, 3, 4, 5} = {7} B  C CS1022

Examples Let A = {1, 3, 5, 7} B = {2, 4, 6, 8} C = {1, 2, 3, 4, 5} Find A  C = {1, 3, 5, 7}  {1, 2, 3, 4, 5} = {1, 2, 3, 4, 5, 7} B  C = {2, 4, 6, 8}  {1, 2, 3, 4, 5} = {2, 4} A – C = {1, 3, 5, 7} – {1, 2, 3, 4, 5} = {7} B  C = (B – C)  (C – B) = ({2, 4, 6, 8} – {1, 2, 3, 4, 5})  ({1, 2, 3, 4, 5} – {2, 4, 6, 8}) = {6, 8}  {1, 3, 5} = {1, 3, 5, 6, 8} N.B.: ordering for better visualisation! CS1022

Information modelling with sets We can build an information model with sets “Model” means we don’t care how it is implemented Essence: what information is needed Example: information model for student record NAME = {namei, ...., namen} ID = {idi, ...., idn} COURSE = {coursei, ...., coursen} Student Info: (namej, idk, courses), where namej  NAME, idk  ID, and courses  COURSE. Student Database is a set of student info: R = {(bob,345,{CS1022,CS1015}), (mary,222,{SX1009,CS1022,MA1004}), (jill,246,{SX1009,CS2013,MA1004}), (mary,247,{SX1009,CS1022,MA1004}), ...} CS1022

Query the Student Database R = {(bob,345,{CS1022,CS1015}), (mary,222,{SX1009,CS1022,MA1004}), (jill,246,{SX1009,CS2013,MA1004}), (mary,247,{SX1009,CS1022,MA1004}), ...} Query to obtain a class list. Give set C, where: C = {(N,I) : (N,I,Courses)  R and CS1022  Courses} = {(bob,345), (mary,222), (mary,247), ...} CS1022

Summary You should now know: What sets are and how to represent them Venn diagrams Operations with sets How to build information models with sets and how to operate with this model CS1022

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 3) Wikipedia’s entry Wikibooks entry CS1022