CSE 21 Mathematics for Algorithm and System Analysis
Total Page:16
File Type:pdf, Size:1020Kb
CSE 21 Mathematics for Algorithm and System Analysis Unit 1: Basic Count and List Section 3: Set (cont’d) Section 4: Probability and Basic Counting CSE21: Lecture 4 1 Quiz Information • The first quiz will be in the first 15 minutes of the next class (Monday) at the same classroom. • You can use textbook and notes during the quiz. • For all the questions, no final number is necessary, arithmetic formula is enough. • Write down your analysis, e.g., applicable theorem(s)/rule(s). We will give partial credit if the analysis is correct but the result is wrong. CSE21: Lecture 4 2 Correction • For set U={1, 2, 3, 4, 5}, A={1, 2, 3}, B={3, 4}, – Set Difference A − B = {1, 2}, B − A ={4} – Symmetric Difference: A ⊕ B = ( A − B)∪(B − A)= {1, 2} ∪{4} = {1, 2, 4} CSE21: Lecture 4 3 Card Hand Illustration • 5 card hand of full house: a pair and a triple • 5 card hand with two pairs CSE21: Lecture 4 4 Review: Binomial Coefficient • Binomial Coefficient: number of subsets of A of size (or cardinality) k: n n! C(n, k) = = k k (! n − k)! CSE21: Lecture 4 5 Review : Deriving Recursions • How to construct the things of a given size by using the same type of things of a smaller size? • Recursion formula of binomial coefficient – C(0,0) = 1, – C(0, k) = 0 for k ≠ 0 and – C(n,k) = C(n−1, k−1)+ C(n−1, k) for n > 0; • It shows how recursion works and tells another way calculating C(n,k) besides the formula n n! C(n, k) = = k k (! n − k)! 6 Learning Outcomes • By the end of this lesson, you should be able to – Calculate set partition number by recursion. – Calculate probability value using Probability Function and Venn Diagrams. CSE21: Lecture 4 7 Why do we need to learn them? • Set partition is an important operation to divide problem and will be used in future lectures. • Probability describes and calculates the likelihood of random events that happens in everyday lives. – Whether it will rain tomorrow? – Can Chargers win in the next game? – … CSE21: Lecture 4 8 CSE 21 Mathematics for Algorithm and System Analysis Unit 1: Basic Count and List Section 3: Set (cont’d) CSE21: Lecture 4 9 Example 24: Set Partitions • A partition of a set B is a collection of nonempty subsets of B such that each element of B appears in exactly one subset. Each subset is called a block of the partition. • Partitions of {1, 2, 3} by the number of blocks: – 1 block: {{1, 2, 3}} – 2 blocks: {{1, 2}, {3}}, {{1, 3}, {2}},{{1}, {2, 3}} – 3 blocks: {{1}, {2}, {3}} CSE21: Lecture 4 10 Solution of Example 24 (1) • Let S(n,k) be the number of partitions of an n-set having exactly k blocks. Given 3-set {1,2,3}, calculate S(3, 2) from smaller size numbers: S(2, 1) and S(2, 2). • By Recursion, first remove element 3 from set{1, 2, 3} – S(2, 1) for {1, 2}:{{1, 2}} – S(2, 2) for {1, 2}:{{1},{2}} • Check how to add element 3 back – One way to add 3 as a separate block:{{1, 2}, {3}} – Two ways to add 3 into existing blocks: {{1, 3}, {2}},{{1}, {2, 3}} • S(3, 2) = S(2, 1) + 2×S(2, 2) CSE21: Lecture 4 11 Solution of Example 24 (2) • Recursion for S(n,k): First remove n from the set {1,..., n} and from the block of the partition in which it occurs, AND add n back. – If n was in a block by itself: partition number is S(n − 1, k − 1). Only one way to add n back: { n}. – If n was in a block with others: partition number is S(n − 1, k). k ways to add n back because there are k blocks. • By Rule of Sum and Product, S(n, k) = S(n−1, k−1) ×1 + k × S(n−1, k). CSE21: Lecture 4 12 Tabular form for S(n, k) k n 1 2 3 4 5 6 7 1 1 2 1 1 S(n,k) 3 13 1 4 17 6 1 5 11 5 2 5 1 0 1 6 13 1 9 0 6 5 1 5 1 7 1--- - - - - - -- 1 CSE21: Lecture 4 13 CSE 21 Mathematics for Algorithm and System Analysis Unit 1: Basic Count and List Section 4: Probability and Basic Counting CSE21: Lecture 4 14 Basic Probability Terms • Universal set ( U), we assume it is finite. • In probability theory, the term “universal set” is replaced by “sample space ”. • probability : If we select elements uniformly at random from a sample space U, the probability of each element of U being selected is 1/| U|. • event : A subset E ⊆ U. If we select elements uniformly at random from U, the probability that selection belongs to the set E is | E|/| U|. CSE21: Lecture 4 15 Definition 4: Probability function and probability space • Let U be a finite sample space and let P be a function from U to R (the real numbers) such that P (t) ≥ 0 for all t and ∑ P ( t ) = 1 . t∈U – P is called a probability function on U. – The pair (U,P) is called a probability space . – P can include events ( E ⊆ U) directly: P ( E ) = ∑ P (t) t∈E – P(E) is called the probability of event E – An element t ∈ U is called an elementary event or a simple event . CSE21: Lecture 4 16 Examples of Probability Function and Probability Space • Suppose U = {H,T} • Flip a coin, if “heads” comes up, we choose H, otherwise we choose T. • Probability function P: suppose that the “probability” of choosing H is 0.4 and the probability of choosing T is 0.6, then P(H) = 0.4, P(T) = 0.6 • Probability space: ( U, P) • P(t) = P(H) + P(T) =1 ∑t∈U CSE21: Lecture 4 17 Theorem 9: Disjoint Events • Disjoint sets : two sets X and Y are disjoint if and if X∩Y = ∅. • Disjoint events: Suppose that ( U, P) is a probability space and that X and Y are disjoint subsets of U, Then P(X∪Y)= P(X)+ P(Y) • Example: • For the coin flip case: P({H, T}) = P({H}) + P({T}) = 1 CSE21: Lecture 4 18 Example 26 : Venn Diagrams • Venn diagram shows the relationship between elements of sets. – The interior of the rectangle represents the sample space U, or universal set U. – The interior of each of the circular regions represents a event in sample space U or a subset of universal set U. • The figure shows four disjoint areas: 1, 2, 3, 4. Calculate results of set operations – (A∪B)c =1 11 AA BB – A−B =2 – A ∩ B=3 22 33 44 – B − A=4 UU CSE21: Lecture 4 19 Example 26 : Venn Diagrams and Probability • P (A) + P (Ac) = P (U) =1 • P(A ∪ B) = P(A−B) + P(A ∩ B) + P(B−A) • P (A − B) = P (A) − P (A ∩ B) 11 AA BB 22 33 44 • P (B − A) = P (B) − P (A ∩ B) UU • P (A ∪ B) = P (A) + P (B) − P (A ∩ B) • P(Ac ∩ Bc) = 1 − P(A) − P(B) + P(A∩B) CSE21: Lecture 4 20 Example 27 : Combining Events • Let A and B be events, – A occurs with probability 7/15; – B occurs with probability 6/15; – The probability that neither of the events occurs is 3/15. • What is the probability that both of the events occur? – P(A∩B) = P(Ac ∩ Bc) + P(A) + P(B) − 1 = 1/15. – Venn diagram: 3/15 AA BB 6/15 1/15 5/15 UU 21 Example 31 : Girls and Boys Sit in a Row • Four girls and two boys sit in a row. Find the probability that each boy has a girl to his left and to his right. – Eligible patterns: gbgbgg, gbggbg, and ggbgbg – 6 Number of all possible patterns: =15 – Possibility: 3/15=1/5 2 • What if they sit in a circle? – Start from a boy in the circle, check eligible positions for the other boy (3) and all possible positions for the other boy (5) – Possibility: 3/5 CSE21: Lecture 4 22 Example 29 : Hypergeometric Probabilities • b light bulbs are chosen at random from B light bulbs of which D are defective. • What is the probability that exactly d of the chosen bulbs are defective? P(E(B,D,b,d )) − • D B D Possible ways for the above problem: d b − d – First choose d bulbs from the D defective bulbs, – AND then choose b-d bulbs from the B-D good bulbs • Overall ways of choose b bulbs: B b − • Probability: D B D d b − d B b CSE21: Lecture 4 23 Example 32 : Dealing Cards from a Standard Deck of 52 Cards • A man is dealt 4 spade cards from an ordinary deck of 52 cards. • If he is given five more cards, what is the probability that three of them are spades? • Another hypergeometric probabilities problem: B=48, D=9, b=5, d=3 • Probability: D B − D 9 48− 9 9! × 39! d b − d 3 5− 3 = = 3!× 6! 2!×37! 48! B 48 b 5 5!43! CSE21: Lecture 4 24 Example 30 : Sampling with Replacement from Six Cards • Given 6 cards numbered 1 to 6, first select one card at random. Then replace the card selected, and select a second card at random.