1 / 25

CS 104: Discrete Mathematics

CS 104: Discrete Mathematics. Chapter 3: Fundamental Structures. Sets (In Book: Chapter 2-sec 2 .1 ). Sets. Set is one of the discrete structures used to represent discrete objects. Many important discrete structures are built using sets. Set Definition:

eve
Download Presentation

CS 104: Discrete Mathematics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 104: Discrete Mathematics Chapter 3: Fundamental Structures

  2. Sets (In Book: Chapter 2-sec 2.1) T. Mai Al-Ammar

  3. Sets • Set is one of the discrete structures used to represent discrete objects. • Many important discrete structures are built using sets. • Set Definition: • A set is an unordered collection of objects, called the elements or membersof the set. • A set is said to contain its elements. a denotes that a in an element of the set A. denote that a is not an element of the set A. • Although sets are usually used to group together elements with common properties, there is nothing that prevents a set from having unrelatedelements , e.g. { a, 2, Ahmed, Riyadh}. T. Mai Al-Ammar

  4. Sets ( Cont. ) • Ways to describe sets : • Roster method: List all members of a set ,if possible, between braces. E.g. • S = { 1, 2, 3} • S = { 1, 3,5,9 … 99 } (( ellipses used )) • Set builder method: characterize all elements in the set by stating the property or properties they must have to be members . • e.g.S contains all odd positive integers less than 100 • N = { 0,1,2,3 , … } Natural numbers • Z = { … , -2, -1, 0, 1, 2, … } integers • Q = { p/q | rational numbers T. Mai Al-Ammar

  5. Sets (Cont.) • Sets can have other sets are members , e.g. S = { N, Z, R } • In sets , the order of elements is not important since sets are unordered. • In sets, the repetition is irrelevant. • The concept of datatypein computer science is built upon the concept of a set, Datatype is the name of a set together with a set of operations that can performed on objects of the set. • E.g. Data type : booleanis the name of set {0,1} and operation on it is • { AND, OR, XOR}. T. Mai Al-Ammar

  6. Sets ( Cont. ) • Equal Sets : • Two sets are equal if and only if they have the same elements, if A and B are sets, then A = B if and only if • e.g. { 1, 2,3 } = { 2 , 3, 1} • { 1 , 2, 2, 3 } = { 1,2, 3 ,3 } • Empty Set ( null set) : • A set that has no elements. It is denoted by or { } . • e.g. a set that contains positive integers less than zero • Singleton Set: • A set with one element. • Empty set is not equal to {} (( singleton set)). T. Mai Al-Ammar

  7. Sets (Cont. ) • Venn Diagram : • Sets can be represented graphically using Venn diagrams. • In Venn diagram, the universal set is represented as a rectangle. • Inside rectangle, circles are used to represent sets. • And points represent elements. U V a T. Mai Al-Ammar

  8. Sets (subsets ) • The set A is said to be a subsetof the set B if and only if every element of A is also an element of B, and B is said to be supersetof A. • is true • To show that A B, find a single element x A such that x B • For every set S: and • Proper subset: • if a set A is a subset of B but A B then A B. • for A B, it must be the case that is true and there must exist an element x of B that is not an element of A: • i.e. x ∉ A) • A = B if and i.e. T. Mai Al-Ammar

  9. Sets ( Cont.) • Examples: • Is {x}  {x}? No • Is {x}  {x}? Yes • Is {x}  {x, {x}}? Yes • Is {x}  {x, {x}}? Yes • Size of a Set: • Let S be a set. If there are exactly n distinct elements in S where n is a nonnegative integer. Then S is a finite set and n is the cardinality of S :|S| • e.g. A is a set of odd positive integers less than 10 • A = { 1, 3, 5, 7, 9 } , |A| = 5 • || = 0 (( has no elements )) T. Mai Al-Ammar

  10. Sets (power set) • Power Set : • If S is a set, then the power set of Sis the set of all subsets of the set S. • The power set of S is denoted by P(S). i.e., P(S)= { x | x  S }. • Examples: • If S={a}, then P(S)={, {a}}. • If S = {a, b}, then P(S)={, {a}, {b}, {a, b}}. • If S = , then P(S)= {} • If S = {{}}, then P(S)= {, {{}} } Fact: If S is finite, |P(S)| = 2|S| . (if |S|=n, |P(S)|=2n) T. Mai Al-Ammar

  11. Sets (Cartesian Products) • The ordered n-tuples ( a1, a2, … an) is the ordered collection that has a1 as its first element and an as its nth element. • Two ordered n-tuple are equal if and only if each corresponding pair of their element is equal. • The Cartesian product of A and B, denoted by A x B , is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B : • Examples: • If A={1, 2}, B={a, b, c} then A x B={(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)} • Facts: • 1. A x B ≠ B x A 2. |A x B| = |A| * |B| • A1 x A2 x … x An = {(a1, a2,…, an) | ai  Ai, for i=1, 2, …, n} T. Mai Al-Ammar

  12. Set Operations (In Book: Chapter 2-sec 2.2) T. Mai Al-Ammar

  13. Sets Operations Union Intersection Disjoint Difference Complement Set Identities T. Mai Al-Ammar

  14. Set operations( Cont.) 1. Union : The unionof two sets A and B, denoted by AB, is the set that contains those elements that are either in A or in B, or in both: A  B = { x | x  A or x  B} e.g. The union of two sets {1,3,5} and { 1,2,3} is { 1, 2, 3,5, } In the figure, the colored area (1,2, and 3) is the union of two sets. T. Mai Al-Ammar

  15. Set operations ( Cont.) 2. Intersection : The intersectionof two sets A and B, denoted by AB, is the set containing those elements in both A and B: A  B = { x | x  A and x  B} e.g. the intersection of two sets {1,3,5 } and {1,2,3} is {1,3} In the figure, the colored area (2) is the intersection of two sets. T. Mai Al-Ammar

  16. Sets Operations (Cont.) • 3. Disjoint sets: • Two sets are said to be disjointif their intersection is the empty set. • Examples: • If A = {1, 3, 5, 7, 9}, and B = {2, 4, 6, 8, 10}, then A  B=Ø • If A = {x | x is a CS major student} and B = {x | x is a IS major student}, then AB=Ø T. Mai Al-Ammar

  17. Sets Operations (Cont.) 4. Difference : The differenceof two sets A and B, denoted by A-B, is the set containing those elements that are in A but not in B: A – B = { x | xA and xB} e.g. If A = {1, 3, 5}, and B = {1, 2, 3}, then A-B = {5}, and B-A = {2}. In the figure, the colored area (1) is the difference of two sets. In general : A-B  B-A T. Mai Al-Ammar

  18. Set Operations (Cont.) • 5. Complement : • The Complementof the set A : is the complement of A with respect to the universal set U, i.e. those elements that are in universal set but not in A . • Therefore, the complement of the set A is U – A • e.g. If U={1, 2, …, 10}, A={1, 3, 5, 7, 9}, then ={2, 4, 6, 8, 10}. • In the figure, the colored area (3,4) is the complement of the first set. T. Mai Al-Ammar

  19. Set Operations ( Cont.) 6. Set Identities T. Mai Al-Ammar

  20. Set Operations (Cont.) 6. Set Identities ( Cont.) : T. Mai Al-Ammar

  21. Set Operations (Cont.) Facts: = and = U A - B = A  There are three ways to proof set identities : Constructing new logical equivalence statements Use membership tables: To indicate that an element is in a set , a 1 is used, to indicate that an element is not in a set , a 0 is used. Venn diagram T. Mai Al-Ammar

  22. Set Operations (Cont.) Example : Use set builder and logical equivalences to establish the first De Morgan Law T. Mai Al-Ammar

  23. Set Operations (Cont.) Example: Prove the following law using Membership table: A  (B  C) = (A  B)  (A  C) T. Mai Al-Ammar

  24. Set Operations (Cont.) Example: Prove the following law using Venn diagram: A  (B  C) = (A  B)  (A  C) A  (B  C) (A  B)  (A  C) T. Mai Al-Ammar

  25. Set Operations (Cont.) • Remark: • Note that |A|+|B| counts each element that is in A but not in B, or in B not in A, exactly once. • Each element that is in both A and B will be counted twice • So, elements in A  B will be subtracted the result, i.e., • |A  B| = |A| + |B| - |A  B| Example: There are 150 CS majors 100 are taking CS530 , 70 are taking CS520 30 are taking both, How many are taking neither? • 150 – (100 + 70 - 30) = 10 T. Mai Al-Ammar

More Related