Skip over navigation

Contents

Review of Recursion

Problems

Table of Contents

Further Reading

To recurse is to

To recur is to

Factorial is

factorial(0) is

Recursion is

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

The function


int example(unsigned int a)
{
    if (a==0) return 0;
    else return example(a+1);
}
is a bad recursive function because

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);
}

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

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

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.

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

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 stack is an example of a ____ data structure.

A queue is an example of a _____ data structure.

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

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

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

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));
}

The following function implements what recursive function?


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

What does the following function do?


int strcmp_i(char *s, char *t)
{
	for(; *s==*t && *s!='\0'; s,t);
	return(*s - *t);
}

True or False: Merge sort is an example of a divide-and-conquer sort.

True or False: All recursive functions can be implemented iteratively.

True or False: All iterative functions can be implemented recursively.

What does this function do?


void mystery(int num)
{
	if (num / 8) mystery(num / 8);
	putchar(num % 8 + '0');
}

This function is an example of what type of recursion?


int fib_r(int n)
{
	if (n<=1) return 1;
	else return(fib_r(n-1) + fib_r(n-2));
}

Which of the following data structures could be considered a recursive data structure?

A recursive data structure is what?

fib(5) is

factorial(4) is

True or False: If a recursive function does not have a base case, the compiler will detect this and display a compiler error.

True or False: A recursive function must have a void return type.

True or False: Recursive calls are usually contained within a loop.

True or False: It is possible to have more than one recursive call within a function.

True or False: Binary search can only be written recursively.

Which of these statements is true about the following code?


int mystery(int n)
{
	if (n>0) return n + mystery(n-1);
	return 0;
}

Which of the following iterative functions is not equivalent to this recursive function?


int mystery(int n)
{
	if(n > 0) return (n + mystery(n - 1));
	return 0;
}

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.

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.

Recursion can be an inefficient way to implement a solution because

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

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

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

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

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

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

The following function implements which operation?


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

The following function implements which operation?


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

Follow Us