cs 103 discrete structures lecture 10 basic structures: sets (1)

63
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)

Upload: maud-dennis

Post on 02-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

The Foundations: Logic and Proofs

CS 103 Discrete Structures Lecture 10Basic Structures: Sets (1)

1Chapter 1 section 1.1 by Dr. Mosaad HassanFirst Midterm Exam2nd Lecture, next week (same time as the lecture)75 minute durationWill cover all lectures delivered before the exam dateWill consist of MCQs, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams If you miss this exam for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. That exam will cover all lectures delivered in the semester. It will consist of writing of proofs, drawing of diagrams and answering questions having 0.5-1 page answers.Basic Structures: Sets, Functions, Sequences, Sums, and MatricesChapter 2With Question/Answer AnimationsChapter SummarySets The Language of SetsSet OperationsSet Identities

SetsSection 2.1Section SummaryDefinition of setsDescribing SetsRoster MethodSet-Builder NotationSome Important Sets in MathematicsEmpty Set and Universal SetSubsets and Set EqualityCardinality of SetsTuplesCartesian ProductIntroductionSets are one of the basic building blocks for the types of objects considered in discrete mathematicsImportant for countingProgramming languages have set operationsSetsA set is an unordered collection of objectsCapital letters (A, B, C) are used to denote sets

The objects in a set are called the elements or members of that set. Lower-case letters (a, b, c) are used to denote elements

Membership of a Setx A denotes that x is an element of the set AExample: lion {tiger, lion, cat}x A denotes that x is not an element of the set AExample: 7 {1, 2, 3, 4}Ways of Describing a SetRoster method

Using set builder notation

Venn diagrams

Describing a Set: Roster MethodListing all members of a set, when possibleExamples{1, 2, 3} is the set containing 1, 2 and 3{1, 1, 2, 3, 3} not appropriate as repetition is not allowed. The correct form is {1, 2, 3}{1, 2, 3} = {3, 2, 1} = {2, 3, 1} since sets are unordered{1, 2, 3, } is a way to denote an infinite set or { } is the empty set, or the set containing no elements. Note that {}Describing a Set: Set Builder Notation Characterize all elements in the set by stating the properties they must have to be membersExamplesE = {x | x is a student at Taibah University}O = {x | x is an odd positive integer less than 10}O = {x Z+ | x is odd and x < 10}Q+ = {x R | x = p/q, for some +ive integers p, q}D = {x | P(x)}, i.e. set of all x for which P(x) is trueSymbols for Sets of NumbersN= {0, 1, 2, 3, } - set of natural numbersZ= {, -2, -1, 0, 1, 2, } - set of integersZ+= {1, 2, 3, } - set of positive integersZ-= {-1, -2, -3, } - set of negative integersR = set of real numbersR+ = set of positive real numbersC = set of complex numbersQ= {p/q | p Z, q Z, q 0} - set of rational numbersEqual SetsTwo sets are equal iff they have the same elementsIf A and B are sets, then A and B are equal (A = B) iff x (x A x B)Examples{1, 3, 5 } = {3, 5, 1} because they have the same elements {-3, -2, -1, 0, 1, 2, 3}= {x | x is an integer and |x| < 4}= {x | x Z, |x| < 4}= {integers between -3 and 3 inclusive}{{1}} {1}Describing a Set: Venn DiagramsThey are used to represent sets graphically

They are often used to indicate the relationships among sets

In Venn diagrams:Rectangles represent the universal set U, which contains all the objects under considerationCircles, inside a rectangle, represent setsPoints represent the particular elements of the setVenn Diagrams: ExampleA Venn diagram that represents the set VV = {a, e, i, o, u}

SubsetSet A is said to be a subset of set B iff every element of A is also an element of BWe use the notation A B to indicate that A is a subset of the set B.A B iff x (x A x B) is true

ExampleA= {2, 4, 6}, B = {1, 2, 3, 4, 5, 6, 7} A B, i.e.,x (x A x B) is true

SubsetsExample: The set of all computer science students at Taibah University is a subset of the set of all students at Taibah University

RemarksEvery non-empty set has at least 2 subsets, & itselfSet A is a proper subset of B (A B) if A B but A B, i.e., A is a proper subset of B if x (x A x B) x (x B x A) is trueSet A = B iff A B and B AA B means A is a superset of B, i.e., B is contained in A. It can be expressed as: x [(x B) (x A)]Sets within SetsSets may contain other sets as members

Examples

A = {, {a}, {b}, {a, b}} and B = {x | x is a subset of the set {a, b}}. Notes: A = B. {a} A , but a A

S = {{1}, {2}, {3}}

T = {{1}, {{2}}, {{{3}}}}

V = {{{1}, {{2}}}, {{{3}}}, {{1}, {{2}}, {{{3}}}}}Notes: V has only 3 elements. 1 {1} {{1}} {{{1}}} The Empty Set = { } {}{ } has zero elements{} has one element {1, 2, 3}?Yes {1, 2, 3}?No {, 1, 2, 3}?Yes {, 1, 2, 3}?Yes{x} {x}?No

Cardinality of a SetIf S is finite, then the cardinality of S, |S|, is the number of distinct elements in SExamplesS = {1, 2, 3, 4, 5}, |S| = 5S = {3, 3, 3, 3, 3}, |S| = 1S = , |S| = 0S = {, {a}, {b}, {a, b}}, |S| = 4If S be the set of odd positive integers less than 10 then |S| = 5If S be the set of letters in the English alphabet then |S| = 26

A set is said to be infinite if it is not finite. The set of positive integers is infinite. Its cardinality is infiniteTuplesThe ordered n-tuple (a1,a2,..,an) is the ordered collection that has a1 as its first element and a2 as its second element and so on until an as its last element2-tuples are called ordered pairs

Two n-tuples are equal iff their corresponding elements are equalThe ordered pairs (a, b) and (c, d) are equal iff a = c and b = d

Power SetThe power set of S, P(S), is the set of all subsets of S

Let S = {0, 1, 2} then P(S) = {, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}Note: |S| = 3 and |P(S)| = 8

If S has n elements then the power set of S has 2n elements

S = {a}, P(S) = {, {a}}

S = {, {}}, P(S) = {, {}, {{}}, {, {}}}Cartesian ProductLet A and B be sets , the Cartesian product of A andB, denoted by A B, is the set of all ordered pairs(a, b), where a A and b B.

A B = { (a, b) | a A b B}

ExampleA = {1, 2}B = {a, b, c}A B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}A B B AA B B A, unless A = B Note: If A = = B, then A B =

ExampleA = {1, 2}B = {a, b, c}A B = {(1, a), (1, b), (1, c) , (2, a), (2, b), (2, c)}B A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)} RelationA subset R of the Cartesian product A B is called a relation from the set A to the set B

The elements of R are ordered pairs, where the first element belongs to A and the second to B

Example

R = {(a, 0), (a 1), (a, 3), (b, 1), (b, 2), (c, 0) , (c, 3)}is a relation from the set {a, b, c} to the set {0, 1, 2, 3}Cartesian Product of Many SetsThe Cartesian product of the sets A1, A2, ... , An isA1 A2 An = {(a1, a2, ... , an) | ai Aifor i = 1,2, ...,n}

ExampleA = {0, 1}B = {1, 2}C = {0, 1 2}A B C = {(0, 1, 0),(0, 1, 1),(0, 1, 2),(0, 2, 0),(0, 2, 1),(0, 2, 2),(1, 1, 0),(1, 1, 1),(1, 1, 2),(1, 2, 0),(1, 2, 1),(1, 2, 2) }Section 1.1: Exercises1. List the members of these sets.a) {x | x is a real number such that x2 = 1}b) {x | x is a positive integer less than 12}c) {x | x is the square of an integer and x < 100}d) {x | x is an integer such that x2 = 2}2. Use set builder notation to give a description of each of these sets.a) {0, 3, 6, 9, 12}b) {-3, -2, -1,0, 1, 2, 3}c) {m, n, o, p}3. Determine whether each of these pairs of sets are equal.a) {1, 3, 3, 3, 5, 5, 5, 5, 5}, {5, 3, 1}b) {{1}}, {1, {1}} c) , {}4. Suppose that A = {2, 4, 6}, B = {2, 6}, C = {4, 6}, and D = {4, 6, 8}. Determine which of these sets are subsets of which other of these sets.

Exercises

Exercises

Exercises

CS 103 Discrete Structures Lecture 11Basic Structures: Sets (2)

31Chapter 1 section 1.1 by Dr. Mosaad HassanFirst Midterm ExamNext lecture (same time as the lecture)75 minute durationWill cover all lectures delivered before the exam dateWill consist of MCQs, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams If you miss this exam for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. That exam will cover all lectures delivered in the semester. It will consist of writing of proofs, drawing of diagrams and answering questions having 0.5-1 page answers.Set OperationsSection 2.2Section SummarySet OperationsUnionIntersectionComplementationDifferenceMore on Set CardinalitySet IdentitiesProving IdentitiesMembership TablesSet OperationsUnionIntersectionComplimentDifference

Set Operations: UnionThe union of the sets A and B, A U B, is the set that contains those elements that are either in A or B, or both. A B = {x : x A x B}

Examples{1, 2, 3} U {3, 4, 5} = {1, 2, 3, 4, 5} {a, b} U {3, 4} = {a, b, 3, 4} {1, 2} U = {1, 2}

Set Operations: IntersectionThe intersection of the sets A and B, A B, is the set containing those elements that are common between A and B. A B = {x : x A x B}

Examples{1, 2, 3} {3, 4, 5} = {3}

{a, b} {3, 4} =

{1, 2} =

Disjoint SetsTwo sets are called disjoint if their intersection is the empty set. A B =

Examples{1, 2, 3} and {3, 4, 5} are not disjoint{a, b} and {3, 4} are disjoint{1, 2} and are disjoint and are disjoint!

Complement of A SetLet U be the universal set. The complement of theset A, , is the complement of A with respect to U,i.e. U - A. = {x : x A } Examples = Let U is the set of the English alphabet lettersA = {a, e, i, o, u} = {b, c, d, j, g, h, j, k, l, p, q, r, s, t, v, w, x, y, z}Let U is the set of all positive integersA = {x | x > 10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Difference of SetsThe difference of A and B, A - B, is the set containing those elements that are in A but not in BA - B = {x : x A x B }The difference of A and B is also called the complement of B with respect to AExamples {1, 2, 3} - {3, 4, 5} = {1, 2} {a, b} - {3, 4} = {a, b} {1, 2} - = {1, 2} S - = S, where S is any set

Symmetric Difference The symmetric difference of sets A and B consists of those elements of the two sets that are not common among them

A B= {x : (x A x B) (x B x A)}= (A - B) (B - A)= (A B) - (A B)

Set Identities

How to Prove An Identity?Prove each set is a subset of the otherUse set builder notation and logical equivalencesUse membership tables

Example - Proving each is a subset of the other

Prove that (A B)c = Ac Bc1. Let x (A B)c x (A B) x A or x B x Ac or x Bc x (Ac Bc) (A B)c Ac Bc 2. Let x Ac Bc x Ac or x Bc x A or x B x (A B) x (A B)c Ac Bc (A B)cFrom 1 and 2 we conclude that (A B)c = Ac Bc Proof using Set Builder Notation

Proof using Membership TablesABA B(A B)cAc BcAc Bc0001111010110110010111110000Element is in the setElement is not in the setProof using IdentitiesShow that[A (B C)]c = (Cc Bc ) Ac

Generalized Unions & Intersections A B C contains those elements that are in at least one of the sets A, B, and CA B C contains those elements that are in all of A, B, and C

Generalized & : ExampleA = {0, 2, 4, 6, 8}B = {0, 1, 2, 3, 4}C = {0, 3, 6, 9}

A B C = {0, 1, 2, 3, 4, 6, 8, 9}

A B C = {0}Generalized Unions & Intersections Generalized UnionThe union of a collection of sets is the set that contains those elements that are members of at least one set in the collection.

Generalized IntersectionThe intersection of a collection of sets is the set that contains those elements that are members of all the sets in the collection

Generalized & : Example 1Let Ai = {i, i+1, i+2, ... } then:

Generalized & : Example 2Ai = {1, 2, 3, ... , i}, i = 1,2, 3, ...

Computer Representation of SetsIf U is a finite set, thenthe number of elements in U cannot be larger than the memory size of the computer being used

If the ordering of the elements of U is a1, a2, ... , an, and if A is a subset of U with the bit string of length n, then the string that represent A has its ith bit as1 if ai A and0 if ai AComputer Representation: Example 1U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}The ordering of elements of U is in the increasing order, that is, ai = i

What bit strings represent the subset of:All odd integers in UAll even integers in UIntegers not exceeding 5 in U10 1010 101001 0101 010111 1110 000012 3456 78910Computer Representation: Example 1The bit string that represents the set of odd integers in U, namely, {1, 3, 5, 7, 9}, has bits in positions first, third, fifth, seventh, and ninth set to 1, and to zero elsewhere.10 1010 1010The string representing the subset of all even integers in U, namely, {2, 4, 6, 8, 10}, is01 0101 0101The string representing the set of all integers in U that do not exceed 5, namely, {1, 2, 3, 4, 5}, is11 1110 0000Computer Representation: Example 2U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}If the bit string for set {1, 3, 5, 7, 9} is 10 1010 1010, what is the bit string for the complement of this set?The bit string for the complement of this set is01 0101 0101, which corresponds to the set{2, 4, 6, 8, 10}Computer Representation: Example 3U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Bit strings for the sets {1, 2, 3, 4, 5} and {1, 3, 5, 7, 9} are 11 1110 0000 and 10 1010 1010, respectively. Find the union and intersection of these sets.

The bit string for the union of these sets is 11 1110 0000 10 1010 1010 = 11 1110 1010, corresponds to the set {1, 2, 3,4, 5, 7, 9}

The bit string for the intersection of these sets is11 11100000 10 1010 1010 = 10 1010 0000, corresponds to the set {1, 3, 5}Section 1.8: Exercises1. Let A be the set of students who live within one mile of school and let B be the set of students who walk to classes. Describe the students in each of these sets.a) A B b) A B c) A - B d) B - A

2. Suppose that A is the set of sophomores at your school and B is the set of students in discrete mathematics at your school. Express each of these sets in terms of A and B.a) the set of sophomores taking discrete mathematics in your schoolb) the set of sophomores at your school who are not taking discrete mathematicsc) the set of students at your school who either are sophomores or are taking discrete mathematicsd) the set of students at your school who either are not sophomores or are not taking discrete mathematicsExercises3. Let A = { l, 2, 3, 4, 5} and B = {0, 3, 6}. Finda) A B b) A B c) A B d) B - A4. Let A = {a, b, c, d, e} and B = {a, b, c, d, e, f, g, h}. Finda) A B b) A B c) A B d) B - A5. Find the sets A and B if A - B = {I, 5, 7, 8}, B - A = {2, l0}, and A B = {3, 6, 9}6. Show that if A and B are sets, thena) A - B = A Bc b) (A B) (A Bc)= A7. Find the symmetric difference of:a) {I, 3, 5} and {I, 2, 3}.b) the set of computer science majors at a university and the set of mathematics majors at that university

Exercises8. Let A = {0, 2, 4, 6, 8, 10}, B = {0, 1 , 2, 3 ,4,5, 6}, and C = {4, 5 , 6, 7, 8 , 9, 10}. Finda) A B C b) A B C c) (A B) C d) (A B) C9. What can you say about the sets A and B if we know that:a) A B=A b) A B=A c) A B = A d) A B= B A e) A B = B - A10. Can you conclude that A = B if A, B, and C are sets such that:a) A C = B C b) A C = B Cc) A B = B C and A C = B CExercises

Exercises

Exercises

Exercises