61A Extra Lecture 2 Thursday, February 5 Announcements 2 - - PowerPoint PPT Presentation

61a extra lecture 2
SMART_READER_LITE
LIVE PREVIEW

61A Extra Lecture 2 Thursday, February 5 Announcements 2 - - PowerPoint PPT Presentation

61A Extra Lecture 2 Thursday, February 5 Announcements 2 Announcements If you want 1 unit (pass/no pass) of credit for this CS 98, you need to: 2 Announcements If you want 1 unit (pass/no pass) of credit for this CS 98, you need to:


slide-1
SLIDE 1

61A Extra Lecture 2

Thursday, February 5

slide-2
SLIDE 2

Announcements

2

slide-3
SLIDE 3

Announcements

  • If you want 1 unit (pass/no pass) of credit for this CS 98, you need to:

2

slide-4
SLIDE 4

Announcements

  • If you want 1 unit (pass/no pass) of credit for this CS 98, you need to:

§Enroll in "Additional Topics on the Structure and Interpretation of Computer Programs"

2

slide-5
SLIDE 5

Announcements

  • If you want 1 unit (pass/no pass) of credit for this CS 98, you need to:

§Enroll in "Additional Topics on the Structure and Interpretation of Computer Programs" §Course control number: 25709

2

slide-6
SLIDE 6

Announcements

  • If you want 1 unit (pass/no pass) of credit for this CS 98, you need to:

§Enroll in "Additional Topics on the Structure and Interpretation of Computer Programs" §Course control number: 25709

  • Extra Homework 1 due Thursday 2/12 @ 11:59pm

2

slide-7
SLIDE 7

Dice

slide-8
SLIDE 8

Hog: The End Game

4

slide-9
SLIDE 9

Hog: The End Game

4

You: 98 Them: 99

slide-10
SLIDE 10

Hog: The End Game

4

You: 98 Them: 99 You: 92 Them: 99

slide-11
SLIDE 11

Hog: The End Game

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99

slide-12
SLIDE 12

Hog: The End Game

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

slide-13
SLIDE 13

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

slide-14
SLIDE 14

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once

slide-15
SLIDE 15

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-16
SLIDE 16

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-17
SLIDE 17

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

The chance to score at least k in n rolls can be computed using tree recursion! You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-18
SLIDE 18

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

The chance to score at least k in n rolls can be computed using tree recursion! Sum over each possible dice outcome t that does not pig out: 
 The chance to roll t times the chance to score at least k - t points using n - 1 rolls. You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-19
SLIDE 19

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

The chance to score at least k in n rolls can be computed using tree recursion! Sum over each possible dice outcome t that does not pig out: 
 The chance to roll t times the chance to score at least k - t points using n - 1 rolls. Base case: The chance to score at least 0 in 0 rolls is 1 (guaranteed) You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-20
SLIDE 20

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

The chance to score at least k in n rolls can be computed using tree recursion! Sum over each possible dice outcome t that does not pig out: 
 The chance to roll t times the chance to score at least k - t points using n - 1 rolls. Base case: The chance to score at least 0 in 0 rolls is 1 (guaranteed) Base case: The chance to score more than 0 in 0 rolls is 0 (impossible) You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

slide-21
SLIDE 21

Hog: The End Game

What is the chance that I'll score at least k points rolling n six-sided dice?

4

The chance to score at least k in n rolls can be computed using tree recursion! Sum over each possible dice outcome t that does not pig out: 
 The chance to roll t times the chance to score at least k - t points using n - 1 rolls. Base case: The chance to score at least 0 in 0 rolls is 1 (guaranteed) Base case: The chance to score more than 0 in 0 rolls is 0 (impossible) You: 98 Them: 99 You: 92 Them: 99 You: 88 Them: 99 You: 80 Them: 99

t Sn : Score from rolling n dice

: A single outcome of rolling once (assuming k > 1)

P(Sn > k) =

6

X

t=2

P(t) · P(Sn−1 > k − t)

(Demo)

slide-22
SLIDE 22

Memoization

slide-23
SLIDE 23

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

slide-24
SLIDE 24

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-25
SLIDE 25

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-26
SLIDE 26

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5)

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-27
SLIDE 27

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(3)

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-28
SLIDE 28

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3)

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-29
SLIDE 29

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-30
SLIDE 30

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-31
SLIDE 31

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-32
SLIDE 32

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-33
SLIDE 33

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-34
SLIDE 34

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-35
SLIDE 35

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-36
SLIDE 36

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-37
SLIDE 37

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-38
SLIDE 38

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-39
SLIDE 39

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-40
SLIDE 40

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-41
SLIDE 41

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-42
SLIDE 42

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-43
SLIDE 43

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-44
SLIDE 44

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-45
SLIDE 45

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-46
SLIDE 46

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-47
SLIDE 47

Recursive Computation of the Fibonacci Sequence

Our first example of tree recursion:

6

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 (Demo)

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-2) + fib(n-1)

slide-48
SLIDE 48

Memoized Tree Recursion

7

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-49
SLIDE 49

Memoized Tree Recursion

7

Call to fib

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-50
SLIDE 50

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-51
SLIDE 51

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-52
SLIDE 52

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-53
SLIDE 53

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-54
SLIDE 54

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-55
SLIDE 55

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-56
SLIDE 56

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-57
SLIDE 57

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-58
SLIDE 58

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-59
SLIDE 59

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-60
SLIDE 60

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-61
SLIDE 61

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-62
SLIDE 62

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-63
SLIDE 63

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-64
SLIDE 64

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-65
SLIDE 65

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-66
SLIDE 66

Memoized Tree Recursion

7

Call to fib Found in cache

fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1

Skipped

http://en.wikipedia.org/wiki/File:Fibonacci.jpg

slide-67
SLIDE 67

Twenty-One (Nim)

slide-68
SLIDE 68

Twenty-One Rules

9

slide-69
SLIDE 69

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total

9

slide-70
SLIDE 70

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0

9

slide-71
SLIDE 71

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more

9

slide-72
SLIDE 72

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

slide-73
SLIDE 73

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

(Demo)

slide-74
SLIDE 74

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

(Demo) Some states are good; some are bad

slide-75
SLIDE 75

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21

(Demo) Some states are good; some are bad

slide-76
SLIDE 76

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20

(Demo) Some states are good; some are bad

slide-77
SLIDE 77

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20

(Demo) Some states are good; some are bad

slide-78
SLIDE 78

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20 19

(Demo) Some states are good; some are bad

slide-79
SLIDE 79

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20 19

(Demo) Some states are good; some are bad

slide-80
SLIDE 80

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20 19 18 17

(Demo) Some states are good; some are bad

slide-81
SLIDE 81

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20 19 18 17

... (Demo) Some states are good; some are bad

slide-82
SLIDE 82

Twenty-One Rules

Two players alternate turns, on which they can add 1, 2, or 3 to the current total The total starts at 0 The game end whenever the total is 21 or more The last player to add to the total loses

9

21 20 19 18 17

(Demo) ... (Demo) Some states are good; some are bad

slide-83
SLIDE 83

Hog Optimal Strategies

slide-84
SLIDE 84

Church Numerals (Homework 2 Challenge Question)