why study discrete math
play

Why Study Discrete Math? Digital computers are based on discrete - PowerPoint PPT Presentation

Why Study Discrete Math? Digital computers are based on discrete units Sets of data (bits). (Rosen, Sections 2.1,2.2) Therefore, both a computers structure (circuits) and TOPICS operations (execution of algorithms)


  1. Why Study Discrete Math? ■ Digital computers are based on discrete units Sets of data (bits). (Rosen, Sections 2.1,2.2) ■ Therefore, both a computer’s ■ structure (circuits) and TOPICS ■ operations (execution of algorithms) • Discrete math can be described by discrete math • Set Definition • Set Operations ■ A generally useful tool for rational • Tuples thought! Prove your arguments. CS 160, Summer Semester 2016 2 Uses for Discrete Math in What is ‘discrete’? Computer Science ■ Consisting of distinct or unconnected elements, not Advanced algorithms & data structures ■ continuous (calculus) Programming language compilers & interpreters. ■ ■ Helps us in Computer Science: Computer networks ■ ■ What is the probability of winning the lottery? Operating systems ■ ■ How many valid Internet address are there? Computer architecture ■ How can we identify spam e-mail messages? ■ ■ How many ways are there to choose a valid password on our Database management systems ■ computer system? Cryptography ■ How many steps are needed to sort a list using a given ■ method? Error correction codes ■ ■ How can we prove our algorithm is more efficient than Graphics & animation algorithms, game engines, etc. … another? ■ i.e. , the whole field! ■ CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 3 4

  2. What is a set? What is a set? ■ An unordered collection of objects ■ Objects are called elements or members of the set ■ {1, 2, 3} = {3, 2, 1} since sets are unordered. ■ Notation ∈ ■ {a, b, c} = {b, c, a} = {c, b, a} = {c, a, b} = {a, c, b} ■ {2} ■ a ∈ B means “a is an element of set B.” ■ {on, off} ■ Lower case letters for elements in the set ■ { } ■ Upper case letters for sets ■ If A = {1, 2, 3, 4, 5 } and x ∈ A, what are the possible values of x? CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 5 6 What is a set? What is a set? Infinite Sets (without end, unending) ■ Infinite vs. finite ■ N = {0, 1, 2, 3, …} is the Set of natural numbers ■ ■ If finite, then the number of elements is called Z = {…, -2, -1, 0, 1, 2, …} is the Set of integers ■ the cardinality , denoted | S | Z+ = {1, 2, 3, …} is the Set of positive integers ■ Finite Sets (limited number of elements) ■ V = {a, e, i, o, u} |V| = 5 ■ V = {a, e, i, o, u} is the Set of vowels ■ ■ F = {1, 2, 3} |F| = 3 O = {1, 3, 5, 7, 9} is the Set of odd #’s < 10 ■ ■ B = {0,1} |B| = 2 F = {a, 2, Fred, New Jersey} ■ Boolean data type used frequently in programming ■ S = {spring, summer, fall, winter} |S| = 4 ■ B = {0,1} ■ B = {false, true} ■ Seasons = {spring, summer, fall, winter} ■ ClassLevel = {Freshman, Sophomore, Junior, Senior} ■ CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 7 8

  3. Example sets Venn Diagram ■ Alphabet ■ Graphical representation of ■ All characters set relations: ■ Booleans: true, false ■ Numbers: ■ N = {0,1,2,3…}- Natural numbers A B ■ Z = {…,-2,-1,0,1,2,…} - Integers ■ Q = - Rationals ■ R , Real Numbers ■ Note that: ■ Q and R are not the same. Q is a subset of R . ■ N is a subset of Z . U CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 9 10 What is a set? Equality ■ A = B is used to show set equality ■ Defining a set: ■ Option 1: List the members ■ Two sets are equal when they have ■ Option 2; Use a set builder that defines set of x that exactly the same elements hold a certain characteristic ■ Thus for all elements x, x belongs to A ■ Notation: {x ∈ S | characteristic of x} if and only if (iff) x also belongs to B ■ Examples: ■ A = { x ∈ Z + | x is prime } – set of all prime ■ The if and only is a bidirectional positive integers implication that we will study later ■ O = { x ∈ N | x is odd and x < 10000 } – set of odd natural numbers less than 10000 CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 11 12

  4. Set Operations: Union Set Operations: Intersection • Operations that take as input sets and • The intersection of sets A and B is the set have as output sets containing those elements in both A and B. • The union of the sets A and B is the set that contains those elements that are either in A or • Notation: A∩B in B, or in both. • The sets are disjoint if their intersection – Notation: A ∪ B produces the empty set. – Example: union of {1, 2, 3} and {1, 3, 5} is? • Example: {1, 2, 3} intersection {1, 3, 5} is? Answer: {1, 2, 3, 5} Answer: {1, 3} CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 13 14 Set Operations: Complement Set Operations: Difference • The difference of A and B is the set of • The complement of set A is the elements that are in A but not in B. complement of A with respect to U, the universal set. • Notation: A - B • Notation: • Aka the complement of B with respect to A • Example: If N is the universal set, what is • Can you define difference using union, the complement of {1, 3, 5}? complement and intersection? Answer: {0, 2, 4, 6, 7, 8, …} • Example: {1, 2, 3} difference {1, 3, 5} is? Answer: {2} CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 15 16

  5. Identities Subsets ■ The set A is a subset of B iff for all elements x of A, x is also an element of B. But not necessarily the reverse… ■ Notation: A ⊆ B ■ {1,2,3} ⊆ {1,2,3} ■ {1,2,3} ⊆ {1,2,3,4,5} ■ What is the relationship of the cardinality |A| <= |B| between sets if A ⊆ B ? CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 17 18 Subset Empty Set ■ Subset is when a set is contained in ■ Empty set has no elements and therefore is another set. Notation: ⊆ the subset of all sets: { } or Ø ■ Proper subset is when A is a subset of B , ■ Is Ø ⊆ {1,2,3}? - Yes! but B is not a subset of A . Notation: ⊂ ■ The cardinality of Ø is zero: | Ø | = 0. ■ ∀ x ((x ∈ A) → (x ∈ B)) ∧ ∃ x ((x ∈ B) ∧ (x ∉ A)) ■ All values x in set A also exist in set B ■ Consider the set containing the empty set: ■ … but there is at least 1 value x in B that is not in A { Ø } ■ A = {1,2,3}, B = {1,2,3,4,5} A ⊂ B, means that |A| < |B|. ■ Yes, this is indeed a set: except for infinite sets, e.g., N ⊂ Z, but |N| = |Z| = infinity Ø ∈ { Ø } and Ø ⊆ { Ø }. CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 19 20

  6. Set Theory Powerset Quiz time: ■ The powerset of a set is the set containing all the subsets of that set. 2001 • A = { x ∈ N | x ≤ 2000 } What is |A|? Infinite ■ Notation: P (A) is the powerset of set A. • B = { x ∈ N | x ≥ 2000 } What is |B|? Yes ■ Fact: | P ( A ) | = 2 | A | . • Is {x} ⊆ {x}? ■ If A = { x, y }, then P (A) = { ∅ , {x}, {y}, {x,y} } Yes • Is {x} ∈ {x,{x}}? ■ If S = {a, b, c}, what is P ( S )? Yes • Is {x} ⊆ {x,{x}}? No • Is {x} ∈ {x}? CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 21 22 Powerset example Example • Number of elements in powerset = 2 n where n = # ■ Consider binary numbers elements in set ■ E.g. 0101 S is the set {a, b, c}, what are all the subsets of S ? • ■ Let every bit position {1,…,n} be an item ■ { } – the empty set ■ Position i is in the set if bit i is 1 ■ {a}, {b}, {c} – one element sets ■ Position i is not in the set if bit i is 0 ■ {a, b}, {a, c}, {b, c} – two element sets ■ {a, b, c} – the original set ■ What is the set of all possible n-bit numbers? and hence the power set of S has 2 3 = 8 elements: ■ The powerset of {1,…n}. {{}, {a}, {b}, {c}, {a, b}, {b, c}, {c, a}, {a, b, c}} CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 23 24

  7. Example (contd.) Why sets? ■ n= 4, i.e, 4 bits, each representing 1 item ■ Programming - Recall a class … it is the set of all its possible objects. 1 2 3 4 ■ We can restrict the type of an object, which is {}, No item present 0 0 0 0 the set of values it can hold. {1}, Item 1 present ■ Example: Data Types 1 0 0 0 {2}, Item 2 present int set of integers (finite) 0 1 0 0 …… char set of characters (finite) {1, 2}, Items 1, 2 present 1 1 0 0 …… ■ Is N the same as the set of integers in a computer? {1, 2, 3}, Items 1, 2, 3 present ■ Is Q or R the same as the set of doubles in a 1 1 1 0 …… computer? {1, 2, 3, 4}, All items present 1 1 1 1 CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 25 26 Order Matters Tuples ■ What if order matters? ■ Order matters ■ Sets disregard ordering of elements ■ Duplicates matter ■ If order is important, we use tuples ■ Represented with parens ( ) ■ If order matters, then are duplicates ■ Examples important too? ■ (1, 2, 3) ≠ (3, 2, 1) ≠ (1, 1, 1, 2, 3, 3) CS 160, Summer Semester 2016 CS 160, Summer Semester 2016 27 28

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend