recursion (summary). two categories translation of recursive definition factorial: fact(1) = 1;...

4
Recursion (summary)

Upload: everett-fields

Post on 17-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Recursion (summary). Two Categories  Translation of recursive definition  Factorial: fact(1) = 1; fact(N) = N * fact(N-1)  Mystery: m(0) = 0; m(1)

Recursion (summary)

Page 2: Recursion (summary). Two Categories  Translation of recursive definition  Factorial: fact(1) = 1; fact(N) = N * fact(N-1)  Mystery: m(0) = 0; m(1)

Two Categories Translation of recursive definition

Factorial: fact(1) = 1; fact(N) = N * fact(N-1)

Mystery: m(0) = 0; m(1) = 3; m(N)=3*m(N-1)+5*m(N-2)

Divide and Conquer

Hanoi: break problem of N into 2 problems of N-1 and “combine” solutions

Guessing game: break problem of N into problem of N/2 and “combine”

Page 3: Recursion (summary). Two Categories  Translation of recursive definition  Factorial: fact(1) = 1; fact(N) = N * fact(N-1)  Mystery: m(0) = 0; m(1)

In-Class Assignment Work in groups of up to three students

Make sure that you turn in your paper with all group member’s names printed CLEARLY at the top

This WILL be graded (though I’m not sure how soon)

Page 4: Recursion (summary). Two Categories  Translation of recursive definition  Factorial: fact(1) = 1; fact(N) = N * fact(N-1)  Mystery: m(0) = 0; m(1)

Questions

1. Write a C function to compute Ackermann’s function (see definition of Ackermann’s function on screen.

2. Write a C function to compute a single element of Pascal’s triangle, pascal(m,n). Use the Pascal’s triangle shown on the screen. HINT: use divide and conquer, at each step converting a problem of with row N into a problem with row N-1.

3. Solve the puzzle shown on the screen.