UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 7 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/
Lecture 7 Notes Goals for this week: Unit FN Functions Permutations: cycle notation, composition Counting functions Probability Random variables, expectation, variance Probability distributions Birthday paradox Random graphs Sterling numbers of the second kind Generated questions on WeBWorK New set on probability Next set on functions by Thursday Poker chips: many problems solved - well done! MT review Tuesday 4/29 (?) 6:30pm, room TBD There is no available classroom on Wednesday 4/30 Practice MT questions posted by ~4/25-26 (Fri-Sat) Draft examples: see the last slides Things to Know will be maintained
Let f: A B be a function Review: Functions f is into (1-1, injective): b B, there is at most one a A s.t. f(a) = b f is onto (surjective): b B, there is at least one a A s.t. f(a) = b f is 1-1 and onto (bijective): b B, there is exactly one a A s.t. f(a) = b For a finite set A, a bijection f: A A is a permutation
Representing Functions (Note: a relation from A to B is a subset of A B, i.e., a set of ordered pairs) FN-4 f: {1,2,3,4} {a,b,c,d} can be represented as a relation: {(1,b),(2,a),(3,c),(4,d)} or by using arrows (domain on left, codomain on right): 1 2 3 4 a b c d
Injective, Surjective, Bijective? 1 2 3 4 a b c 1 2 3 a b c d 1 2 3 4 a b c d
Boolean Functions of K Variables F : {0,1} K {0,1} Example: F(x,y) = x AND y x y F(x,y) 0 0 0 0 1 0 1 0 0 1 1 1 How many Boolean functions of K variables are there?
Boolean Functions With Don t-cares F : {0,1} K {0,1,X} X = don t-care x y z F(x,y,z) 0 0 0 1 0 0 1 X 0 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 1 0 X 1 1 1 0 How many Boolean functions of K variables are there when don tcares are allowed?
Residue (mod M) Function M = modulus Residue (mod M) = remainder after dividing by M f: Z {0, 1,, M 1} -4-3 -2-1 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 f(n) = n (mod 7) Is f an injection? Is f a surjection? Is f a bijection?
Representing Functions Two line notation: matrix-like, with domain elements on top row and codomain elements on bottom. Same idea as set of pairs, different notation
Representing Permutations f: A A = {(1,2),(2,3),(3,1),(4,6),(5,7),(6,5),(7,4),(8,8)} 2-line Matrix notation Cycle notation: use only if f is a permutation! 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 = (1 2 3)(4 6 5 7)(8) -1 = (3 2 1)(7 5 6 4)(8)
Composition Composition of permutations: from right to left Denoted with symbol Given A = {1,2,3,4,5,6}, write the permutation (1,2,3) (2,3,4) (3,4,5) (4,5,6) in cycle form Notation: (4,5,6) is the same as (1)(2)(3)(4,5,6) we leave out the length-1 cycles Observe: 4 5 3 4 5 6 6 4 5 3 4 2 3 2 3 1 1 2 Answer: (4)(56)(3)(21) = (56)(21)
Checkpoint Give the two-line (matrix) notation for the permutation g: {1, 2, 3, 4} {1, 2, 3, 4}, x g(x) 1 2 A. 1 2 3 4 2 3 1 2 3 4 3 4 B. 1 2 3 4 4 1 2 1 3 4 C. 1 2 3 4 2 3 4 1 D. 1 2 3 4 1 4 3 2 E. None of the above.
Checkpoint Give the (one-line) cycle notation for the permutation g: {1, 2, 3, 4} {1, 2, 3, 4}, x g(x) 1 2 A. (1,2,3,4) 2 3 B. (2,3,4,1) 3 4 C. (1,2)(2,3)(3,4)(4,1) 4 1 D. (1,2,3)(4) E. None of the above.
Checkpoint What is the composition of the following two permutations on {1, 2, 3, 4, 5}? f = (1, 2, 3)(4, 5) g = (1)(2)(3, 4, 5) f g =? A. (1, 2, 3)(4, 5) B. (1)(2)(3, 4, 5) C. (1, 2, 4, 3)(5) D. (1, 2, 3, 5)(4) E. None of the above.
Counting Functions Given two sets, how many ways can we make a mapping named f between them? What if f is an injection, surjection or bijection?
Counting Functions If we know A and B, how many functions are there from A to B? A: A B B: C( A, B ) C: A + B D: B A E: B! Each function is determined by how we assign elements of B to elements of A. We can think of this as a list: f(a 1 ), f(a 2 ), f(a 3 ), A slots, with B choices for each slot Product Rule: B A functions from A to B
Counting Injections How many injections are there from A into B? (assume A < B ) A: A B B: C( A, B ) C: A + B D: P( B, A ) E: B! Again, think of this as a list: f(a 1 ), f(a 2 ), f(a 3 ), Injectivity can t have repeated images B choices for the first slot B - 1 choices for the second slot Product Rule: P( B, A ) injections from A into B
Counting Surjections How many surjections are there? (for surjections, will need to assume A > B ) (this is trickier!) Can use partitions and Stirling numbers of the second kind (will get to this) But we can already answer variants or subcases of this question, for arbitrary A and B ( How many functions from A to B have exactly k elements in the image? ) Example: How many functions from {1, 2, 3, 4} to {a, b, c, d, e} have exactly two elements in the image? E.g., {(1,a), (2,a), (3,c), (4,c)}
Counting Functions How many functions f: {1, 2, 3, 4} {a, b, c, d, e} have exactly two elements in the image? Idea: Partition {1, 2, 3, 4} into exactly two nonempty subsets, then assign elements of the codomain as images for each of these subsets Case (4 = 1 + 3): pick one domain element to have a unique image (codomain element), then choose a second codomain element to which the other three domain elements are mapped C(4,1) 1 C(5,1) C(4,1) = 80 Case (4 = 2 + 2): Partition the domain into two subsets of size two; pick two codomain elements to which these subsets are mapped C(4,2) C(5,2) = 60 Total = 80 + 60 = 140
A Probability Question What is the probability that a random function from {1, 2, 3, 4} to {a, b, c, d, e} has exactly two elements in its range? 5 4 = 625 total functions 140 / 625 = 0.224
Random Variables Definition. In a probability space (U,P), we say that X: U R is a random variable. Example. Flip a fair coin four times. Some associated random variables: X = number of heads that appear Y = result of second flip Z = number of switches from H to T or vice versa What are possible values of X? What are possible values of Y? What are possible values of Z? Each value of a given random variable corresponds to an event (subset of U).
Another Probability Question In a room with n people, what is the probability that two people have the same birthday? Assume that all possible birthdays are equally likely, and there are only 365 of them. Let A be the event that two people in the same room have the same birthday. P(A) = 1 P(A c )
Birthdays P(A) = 1 P(A c ) Let B i be the probability that person i has a different birthday than persons 1, 2,, i-1 Note: B 1 = 1
Birthdays Let s try to calculate P(A c ), the probability that no two people among persons 1,, n have the same birthday: P(A c ) = B 1 B 2 B n What is B 2? B 2 = because one birthday has been taken so far B i =
The Birthday Paradox Let s try to calculate P(A c ), the probability that no two people among 1,, n have the same birthday: P(A c ) = B 1 B 2 B n P(A c ) = ( ) ( ) ( = (1 =(! )! ) ( ) (1 ) (1 ) ) What is P(A c ) when n = 1? What is P(A c ) when n = 23?
Closing the Loop No birthday gets hit twice reminds you of an injection! Probability that a random function from {1, 2, 3,, n} to {1, 2, 3, 4,, 364, 365} is an injection is
Problems 7 P7.1 Seven vertices of a cube are marked by 0 and one vertex by 1. You may repeatedly select an edge and increase by 1 the numbers at the ends of that edge. Your goal is to reach (a) 8 equal numbers, (b) 8 numbers divisible by 3. For each of (a), (b) explain whether or not your goal is achievable. You must solve both (a) and (b) for credit. P7.2 (2n + 1) persons are located in a paintball arena so that their mutual distances are all distinct. For purposes of this problem, the paintball arena is a region in the Euclidean plane, and all distances are Euclidean distances. Simultaneously, each person shoots a paintball at his/her nearest neighbor. Prove each of the following. (Each part is worth a separate poker chip.) (a) At least one person is not shot at. (b) Nobody is shot more than five times. (c) No two paintballs have paths that cross each other. (d) The set of segments formed by the paintball paths does not contain a closed polygon.
Problems 7 (cont.) P7.3 A car must be driven completely around a circular track. There is just enough gasoline for the car to get around the track, but the gasoline has been distributed among some number of depots along the track. Prove that no matter how many depots there are, and no matter how the gasoline is distributed among the depots, there is always some depot where the car can start with an empty tank and, by using the gasoline at the depots it passes, get completely around the track.
Fun (from Lecture 6) If two sets can be put into 1-1 correspondence, their cardinalities are equal. Cardinality of infinite sets: very interesting! Elvis s Hotel : although it s always crowded, you still can find some room Elvis s Hotel has Rooms 1, 2, 3, Every room is occupied by a guest. One person arrives. Can he be accomodated? Five people arrive. Can they be accomodated? N people arrive. Can they be accomodated?
Fun (from Lecture 6) If two sets can be put into 1-1 correspondence, their cardinalities are equal. Which set has larger cardinality: R (reals) or (0,1)? SAME N (counting numbers) or N N = Q + (positive rationals)? N (counting numbers) or R + (positive reals)?
MT Practice Problems (draft 140421) A valid license plate must be made of 7 characters, coming from the set of 26 letters {A, B,, Z} and 10 digits {0,1,, 9}. All of the characters must be distinct and at most 2 letters can be used. How many valid license plates are there? How many five-digit numbers exist such that: // note: solve each of (a), (b), (c), (d) separately No digit appears more than once? The number is divisible by 5? The number is even? Exactly three of its digits are even? Note that a number cannot have a leading digit of 0. How many rearrangements are there of the letters in the word LOLLIPOP? Charles has twelve identical tennis balls, five identical bones, and two dog toys that he wants to distribute to his five dogs. If every dog must receive at least one tennis ball and two dog toys cannot be sorted to the same dog, how many ways can Charles distribute the items? There are N nickels and 3 dimes in a coin collection. How many ways can the coins be stacked such that every nickel is touching a dime? Give your answer in terms of N. What is the coefficient of x 3 y 2 in the expansion of (3x + 2y) 5? If f = (12)(34)(56), g = (135)(246), and h = (654321) are three permutations in cycle form, what is the cycle form of???? In how many ways can Oliver place ten distinctly colored balls into five distinctly colored urns if each urn can only hold two balls? Jane randomly removes three cards from a standard deck of cards. What is the probability that They form a triple, i.e., three of a kind? They are all the same color? They form a pair and a single? They form three singles of different suits? Every week, Billy buys a lottery ticket for $10 with a one-in-a-billion chance at winning $100,000,010 and a one-in-a-hundred chance at winning $110. What is his expected return After 10 weeks? After 10 weeks if he buys 3 lottery tickets every week?
MT Practice Problems (draft 140421) At every move, an ant travels one unit to the left or one nit to the right with equal probability. What is the chance that the ant is at its starting point after 2 moves? 4 moves? 6 moves? 2N moves? What is the probability that in a room of seven people, No two have the same birthday (assuming there are 365 equally likely, possible birthdays)? Some two have the same birthday? A total of five people are at a social event. If initially nobody has met anybody, in how many orders can the people meet each other if everyone is to meet everyone else? Marissa has three $10 bills, four $50 bills, and one $100 bill in her pocket. If she just ordered a five-gallon tub of boba for $110 at the local tea silo, what is the probability that she can pay for her purchases (possibly receiving change in return) if She draws two bills out at random? She draws three bills out at random? She draws four bills out at random? She draws five bills out at random? A team of N technicians has an N / (N+2) chance of fixing a router. If the company dispatches at random 1, 2, or 3 technicians to fix a router, what is the probability that The router gets fixed on the first dispatch of technicians? The router gets fixed in no more than two dispatches of technicians? John and Sarah play games of Rock, Paper, Scissors in which each randomly chooses Rock, Paper, or Scissors at every turn. Rock beats Scissors, which beats Paper, which in turn beats Rock. What is the expected number of games they play If they play until one person wins? If they play until John wins? If they play until Rock, Paper, and Scissors have each been chosen at least once? In how many ways can 5 boys and 5 girls sit in a row if each must sit next to at least one person of the same gender? In how many ways can 5 boys and 5 girls sit in a circle such that no two boys sit next to each other? Notice that two arrangements that are obtainable from each other by rotation are considered to be the same arrangement. John tosses a coin five times. If he gets heads, he moves a marker two units to the right. If he gets tails, he moves the marker one unit to the left. If the marker is initially at the center of a circular platform of radius five units, what is the probability that the marker falls off of the platform as a result of the five-move sequence?
MT Practice Problems (draft 140421) In order to get past pipes in his game of Flappy Bird, John found that he has to tap his phone twice in every two-second window (i.e., twice in [0,2 seconds), twice in [2,4 seconds), etc.) with the second tap being no less than 0.3 seconds after the first tap. If John taps two times at random in every two-second window, what is The probability that John gets past the first pipe? John s expected score, i.e., number of pipes he gets past? John s expected score if the second tap must be after the 1.5-second mark in every two-second window? CHALLENGE (harder than any MT question, could be a bonus type of question): Suppose John plays a different version of Flappy Bird and must tap his phone three times every three seconds, with the difference in time between successive taps being no less than 0.3 seconds in order to get past a pipe. If he taps three times at random in every three-second window, what is his new expected score? CHALLENGE (harder than any MT question, could be a bonus type of question): A beetle, starting at the origin on a coordinate plane, travels one unit upwards or one unit rightwards at every turn with equal probability. After 2N turns, the beetle is at location (N,N). What is the probability that the beetle has never once been at a location (x,y) such that y > x?