1 of 96

CSE 312 Recitation 2

Please feel free to ask questions before, during, or after section!

Announcements

  • PSet 1 due Tues 1/18 @ 11pm Pacific
  • PSet 2 out Friday
    • Will have another partner matching form if you need a partner

Agenda

  • Practice with harder questions!

Slides originally written by Alex Tsun & TA’s (William Howard-Snyder, Mitchell Estberg, Maggie Jiang, Ege Caglar).

2 of 96

Super Mario Bros Example

Video game characters Mario and Luigi are trying to advance through levels of the game to save Princess Peach. Before they attempt the first two levels, they enter a Toad House that may provide powerups to increase their chances of beating the levels. For simplicity, assume that if they receive a powerup in the Toad House, then they retain it for both of the first two levels.

Suppose that they have a 1/4 chance of obtaining a powerup from the Toad House. If they have a powerup, they will beat any given level with probability 7/10. If they do not receive a powerup, they will beat any given level with probability 4/10.

3 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

4 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

5 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

6 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

Values needed for numerator are given, but…

How can we find P(W1) if it depends on their powerup status?

7 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

LTP

8 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

LTP

Plug given probabilities

9 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

LTP

Plug given probabilities

Simplify

10 of 96

Super Mario Bros Example

(a) If Mario and Luigi defeated the first level, what is the probability that they received a powerup from the Toad House?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇C be the event that they did not receive a powerup, and 𝑊ᵢ be the event that they win level i.

Bayes’

LTP

Plug given probabilities

Unintuitive, but note low P(T) and how�P(T | W1) > P(T)!

11 of 96

Super Mario Bros Example

(b) If Mario and Luigi defeat the first level, what is the probability that they lose in the second level?

12 of 96

Super Mario Bros Example

(b) If Mario and Luigi defeat the first level, what is the probability that they lose in the second level?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇 C be the event that they did not receive a powerup, 𝑊ᵢ be the event that they win level i, and 𝑊 Ci be the event that they did not win level i.

13 of 96

Super Mario Bros Example

(b) If Mario and Luigi defeat the first level, what is the probability that they lose in the second level?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇 C be the event that they did not receive a powerup, 𝑊ᵢ be the event that they win level i, and 𝑊 Ci be the event that they did not win level i.

Want to find 𝑷 (𝑊 C2 | 𝑊1)... can we try Bayes’?

𝑷 (𝑊 C2 | 𝑊1) = 𝑷 (𝑊1 | 𝑊 C2)𝑷 (𝑊 C2) � 𝑷 (𝑊1 )

14 of 96

Super Mario Bros Example

(b) If Mario and Luigi defeat the first level, what is the probability that they lose in the second level?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇 C be the event that they did not receive a powerup, 𝑊ᵢ be the event that they win level i, and 𝑊 Ci be the event that they did not win level i.

Want to find 𝑷 (𝑊 C2 | 𝑊1)... can we try Bayes’?

𝑷 (𝑊 C2 | 𝑊1) = 𝑷 (𝑊1 | 𝑊 C2)𝑷 (𝑊 C2) � 𝑷 (𝑊1 )

???�Does not make sense contextually

15 of 96

Super Mario Bros Example

(b) If Mario and Luigi defeat the first level, what is the probability that they lose in the second level?

Let 𝑇 be the event that they received a powerup from the Toad House, 𝑇 C be the event that they did not receive a powerup, 𝑊ᵢ be the event that they win level i, and 𝑊 Ci be the event that they did not win level i.

Let’s try a different approach:

Def. Conditional Prob.

16 of 96

Super Mario Bros Example

Def. Conditional Prob.

17 of 96

Super Mario Bros Example

Numerator: Lose level 2 and win level 1… two cases (powerup vs. no powerup)

Multiple cases → Use LTP to break down the cases!

Def. Conditional Prob.

LTP

18 of 96

Super Mario Bros Example

Def. Conditional Prob.

LTP

Def. Conditional Prob.

19 of 96

Super Mario Bros Example

Def. Conditional Prob.

LTP

LTP (same as part (a))�

Def. Conditional Prob.

20 of 96

Super Mario Bros Example

Def. Conditional Prob.

LTP

LTP (same as part (a))

Def. Conditional Prob.��Plug values in��Simplify

21 of 96

Robot Example

Suppose Joe is a k-legged robot, who wears a sock and a shoe on each leg. Suppose he puts on k socks and k shoes in some order. Each action is specified by saying whether he puts on a sock or a shoe, and saying which leg he puts it on. In how many ways can he put on his socks and shoes in a valid order? We say an ordering is valid if, for every leg, the sock gets put on before the shoe. Assume all socks are indistinguishable from each other, and all shoes are indistinguishable from each other.

22 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

23 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

24 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

25 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

26 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

27 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k

28 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

29 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

30 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

31 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

32 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

33 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

34 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Count Something Else

35 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Count Something Else

  • here we are counting choices

36 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else

37 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

38 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

39 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

  • map the problem to something else that you know how to count

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

40 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

41 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

42 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

43 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

What are some possible approaches?

Brute Force

k

k

k-1

k

k-1

k

k-1

k-1

Pattern Searching

  • look for a pattern you can make use of in the brute force approach

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

Count Something Else

  • here we are counting choices
  • we could (and probably should) count something else
  • orderings? assignments?

44 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

45 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects?

46 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

47 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong?

48 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid:

49 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

50 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this?

51 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

52 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

sock comes before shoe!

53 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

sock comes before shoe!

this counts both,

54 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

sock comes before shoe!

this counts both, so divide by 2

55 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

sock comes before shoe!

this counts both, so divide by 2

for each leg

56 of 96

Robot Example

A k-legged robot, puts on k socks and k shoes in some order. An ordering is valid if, for every leg, the sock gets put on before the shoe. All socks are indistinguishable from each other, and all shoes are indistinguishable from each other. How many ways can he put on his socks and shoes in a valid order?

Simplify, then Complicate

  • map the problem to something else that you know how to count
  • look at one example ordering:

sock1, shoe1, sock2, shoe2….

  • another: sock1,sock2,shoe1,shoe2..
  • more orderings (perhaps ignoring parts and over/under counting)
  • then deal with over/under counting

sock1, shoe1, sock2, shoe2 vs. sock1,sock2,shoe1,shoe2..

these are distinct orderings of how many objects? (2k)!

what’s wrong? count invalid: shoe1,sock1, sock2, shoe2…

how do we address this? each leg has one valid order

sock comes before shoe!

this counts both, so divide by 2

for each leg

(2k)!

2

k

57 of 96

Restaurant Example

Suppose n people sit around a table. Each person orders a different dish, but the waiter did not mark positions unfortunately. He has the correct n dishes, but gives a random dish to each person (each of the n! assignments is equally likely). What is the probability that no one has the dish they ordered placed in front of them?

58 of 96

Restaurant Example

Let E be the event that no one gets their dish

Let Ei be the event that the ith person does not get their dish.

Initial approach: people getting their correct dishes are independent events…?

59 of 96

Restaurant Example

The events are not independent because if one person does not get their dish it changes the probability that another person does not get their own dish

  • No easy independence shortcuts :(

60 of 96

Restaurant Example

Let be all the possible ways that the waiter could return the group’s dishes (with no restrictions). Let E be the event that no one gets their dish.

What is the size of ?

61 of 96

Restaurant Example

Let be all the possible ways that the waiter could return the group’s dishes (with no restrictions). Let E be the event that no one gets their dish.

What is the size of ?

62 of 96

Restaurant Example

Let be all the possible ways that the waiter could return the group’s dishes (with no restrictions). Let E be the event that no one gets their dish.

What is the size of ?

What is the size of ?

63 of 96

Restaurant Example

Let be all the possible ways that the waiter could return the group’s dishes (with no restrictions). Let E be the event that no one gets their dish.

What is the size of ?

What is the size of ?

64 of 96

Restaurant Example

Remember: If a set is hard to count, maybe we should try counting its complement

65 of 96

Restaurant Example

Remember: If a set is hard to count, maybe we should try counting its complement

Let be the event that the ith person does get their own dish back. Then,

66 of 96

Restaurant Example

Remember: If a set is hard to count, maybe we should try counting its complement

Let be the event that the ith person does get their own dish back. Then,

Question: Suppose n people order n different dishes. Unfortunately, the waiter did not mark positions. He has the correct n dishes, but gives a random dish to each person. What is the probability that no one has the dish they ordered placed in front of them?

67 of 96

Restaurant Example

Applying the Inclusion-Exclusion Rule we get

68 of 96

Restaurant Example

Applying the Inclusion-Exclusion Rule we get

69 of 96

Restaurant Example

Each k-tuple in the equation (i.e. singles, doubles, etc.), represents the number of dish assignments where exactly k people get their correct dish

k-tuple = (# of ways you can choose groups of k people) x (# of ways you can assign the correct dishes to that group)

Let’s first try to come up with a formula for the number of ways you can choose groups of people

70 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are their?

71 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are their?

72 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are their?

73 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are their?

74 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are there?

75 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are there?

76 of 96

Restaurant Example

How many individuals are there?

How many pairs are there?

How many triplets are there?

77 of 96

Restaurant Example

Have we made progress??

78 of 96

Restaurant Example

Have we made progress??

# of groups of 1 person

# of groups of 2 people

# of groups of n people

79 of 96

Restaurant Example

Have we made progress??

# of groups of 1 person

# of groups of 2 people

# of groups of n people

# of dish assignments s.t. first 1 person has their dish

# of dish assignments s.t. first 2 people have their dishes

# of dish assignments s.t. first 3 people have their dishes

80 of 96

Restaurant Example

Have we made progress??

81 of 96

Restaurant Example (Recap)

  • We are trying to find the probability that no one gets the dish that they originally ordered.

82 of 96

Restaurant Example (Recap)

  • We are trying to find the probability that no one gets the dish that they originally ordered.
  • Our current approach is trying to count the complementary set and apply our complementary counting rule:

83 of 96

Restaurant Example (Recap)

  • We are trying to find the probability that no one gets the dish that they originally ordered.
  • Our current approach is trying to count the complementary set and apply our complementary counting rule:

84 of 96

Restaurant Example (Recap)

  • We are trying to find the probability that no one gets the dish that they originally ordered.
  • Our current approach is trying to count the complementary set and apply our complementary counting rule:

85 of 96

Restaurant Example (Recap)

  • We are trying to find the probability that no one gets the dish that they originally ordered.
  • Our current approach is trying to count the complementary set and apply our complementary counting rule:

86 of 96

Restaurant Example

Almost there!

The number of ways for the the first k out of n people to get the dishes that they ordered (i.e. number of dish assignments s.t. k people have their own dish).

87 of 96

Restaurant Example

Almost there!

The number of ways for the the first k out of n people to get the dishes that they ordered (i.e. number of dish assignments s.t. only k people have their own dish).

88 of 96

Restaurant Example

Size of event space:

89 of 96

Restaurant Example

Size of event space:

90 of 96

Restaurant Example

Size of event space:

k-tuples from before

91 of 96

Restaurant Example

Size of event space:

92 of 96

Restaurant Example

Size of event space:

93 of 96

Restaurant Example

The probability that no one gets their dish back is

94 of 96

Restaurant Example

The probability that no one gets their dish back is

95 of 96

Restaurant Example

As n approaches infinity the probability that no one gets their dish converges

96 of 96

Restaurant Example (Bonus)

Here’s another approach that uses less counting