1
h16
CS16 S17
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone")

h16: Homework 16: Recursive Functions

ready? assigned due points
true Tue 06/06 12:30PM Thu 06/08 12:30PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
In place of that, we drop the two lowest scores (if you have zeros, those are the two lowest scores.)


PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!

1.(4 pts) How does a recursive function know when to stop recursing?

2.(8 pts) What is a LIFO scheme and how does it relate to stacks?

3.(8 pts) What is stack overflow?

4.(20 pts) Write a recursive function program to find the nth element in the following arithmetic numerical sequence: 3, 11, 27, 59, 123, … You can use a separate sheet of paper for this answer and staple it to this one.

Hint: You first have to figure out what is the recursive pattern. You also have to identify the base case. If you cannot write out the program in the space provided below, then print out the program on a separate sheet of paper and attach that to this homework. Please do not use more than 1 page, one sided.

Some correct example outputs would look like this (there is no repeating loop - these are 2 separate runs):

Which element of the sequence would you like to know?
4
Element number 4 in the sequence is 59.


Which element of the sequence would you like to know?
7
Element number 7 in the sequence is 507.