This page requires JavaScript, which you
don't seem to have. Please try a different browser.

Scroll through the page to review your answers. The correct answer is
highlighted in
green.
Your incorrect answers (if any) are highlighted in
red.
If you'd like to take the test over again, click the reset button at the end of the test.

To recurse is to

(A)
Practice recursion

(B)
Swear again

(C)
Neither of the above

To recur is to

(A)
Practice recursion

(B)
Swear again

(C)
Neither of the above

Factorial is

(A)
a good introductory example of recursion, but a function better
implemented iteratively for efficiency reasons.

(B)
a good introductory example of recursion, and a function best
implemented recursively.

(C)
a bad introductory example of recursion as it hard to implement
recursively.

factorial(0) is

(A)
0

(B)
1

(C)
Infinity

(D)
Undefined

(E)
None of the above

Recursion is

(A)
a powerful construct theoretically, but rarely used in actual programs.

(B)
a weak construct theoretically rarely used in actual programs.

(C)
a powerful construct theoretically, often used in certain applications
that benefit from recursive methods.

Which of the following is not a requirement for a recursive function?

(A)
It has two base cases.

(B)
It has a recursive case

(C)
Its recursive case approaches a base case.

The function

int example(unsigned int a)
{
if (a==0) return 0;
else return example(a+1);
}

is a bad recursive function because

(A)
it has no recursive case.

(B)
it has no base case.

(C)
the recursive case does not approach the base case.

Is the following function circular?

int syracuse(int n)
{
if (n==1) return 0;
else if (n % 2 != 0) return syracuse(n/2);
else return 1 + syracuse(3*n + 1);
}

(A)
Yes

(B)
No

(C)
We don't know.

True or False: A call stack is made up of frames.

(A)
True

(B)
False

True or False: During program execution, the call stack can be empty.

(A)
True

(B)
False

True or False: Because a recursive function calls itself, a different
mechanism than the call stack is used to keep track of the function calls.

(A)
True

(B)
False

As a data structure, a call stack is most analogous to

(A)
A supermarket line

(B)
A cafeteria tray dispenser

(C)
A small family of weebles

(D)
A genealogical family chart

If you were to draw out the function call tree for Fib3, how many
function calls would there be in terms of big-O notation?

(A)
O(n^{2})

(B)
O(2^{n})

(C)
O(n!)

(D)
O(3^{n})

A stack is an example of a ____ data structure.

(A)
FIFO

(B)
LIFO

A queue is an example of a _____ data structure.

(A)
FIFO

(B)
LIFO

True or false: Regardless of implementation, the closed-form solution to
the Fibonacci problem is always more efficient than a recursive
implementation.

(A)
True

(B)
False

True or false: A linearly recursive function always has the recursive
call at the end of the function.

(A)
True

(B)
False

True or false: Tail recursion is a form of linear recursion.

(A)
True

(B)
False

The following function is an example of what form of recursion?

int mystery(int n, int k)
{
if (k == 0 || n == k) return(1);
else return(mystery(n-1,k) + mystery(n-1,k-1));
}

(A)
Linear recursion

(B)
Binary recursion

(C)
Nested recursion

(D)
Mutual recursion

The following function implements what recursive function?

int mystery(char *s)
{
if (*s=='\0') return 0;
else return(1 + mystery(s+1));
}

int mystery(int n)
{
int sum = 0;
while (n > 0) {
sum = sum + n;
n--;
}
return sum;
}

(B)

int mystery(int n)
{
int j = 0, sum = 0;
while (j < n) {
j++;
sum = sum + j;
}
return sum;
}

(C)

int mystery(int n)
{
int sum;
while (n > 0) {
sum = 0;
sum = sum + n;
n--;
}
return sum;
}

True or False: When a recursive solution's elegance outweighs its
overhead (memory, time, efficiency, etc), and when it is much less
complex than an iterative solution, you would most likely choose to
use the recursive solution.

(A)
True

(B)
False

True or False: You should always use a recursive solution rather
than an iterative solution when you are sure that that recursive
solution will not overflow the call stack.

(A)
True

(B)
False

Recursion can be an inefficient way to implement a solution because

(A)
using the call stack to store states adds significant overhead.

(B)
calling a function multiple times could be reduced to looping, which
might better done with a looping structure such as a while construct.

(C)
Both of the above.

True or False: Recursion happens when an algorithm does not use a loop.

(A)
True

(B)
False

True or False: A function can be considered recursive if it has a direct
or an indirect call to itself.

(A)
True

(B)
False

True or False: Infinite recursion can occur when a recursive algorithm
does not contain a base case.

(A)
True

(B)
False

True or False: Infinite recursion can occur when a recursive algorithm
contains a base case.

(A)
True

(B)
False

True or False: Infinite recursion can occur when the base case is never
reached by the algorithm.

(A)
True

(B)
False

A solution to a 64-disk Towers of Hanoi problem requires how many disks
to be moved?

(A)
64

(B)
2^64 - 1

(C)
64^2 - 1

(D)
64^64 - 1

(E)
None of the above.

The following function implements which operation?

int mystery(tree_t *tree)
{
if (tree != NULL) {
printf("%d ", tree->data);
mystery(tree->left);
mystery(tree->right);
}
}

(A)
A pre-order traversal.

(B)
An in-order traversal.

(C)
A post-order traversal.

(D)
None of the above.

(E)
All of the above.

The following function implements which operation?

int mystery(tree_t *tree)
{
if (tree != NULL) {
mystery(tree->right);
printf("%d ", tree->data);
mystery(tree->left);
}
}