C++ CH 20 - Recursion

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How many times will the following function call itself if 5 is passed as the argument? void showMesssge(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n-1); } }

5

When recursion is used on a linked list, it will always display the contents of the list in reverse order.

False

A problem can be solved with recursion if it can be broken down into successive smaller problems that are the same as the overall problem.

True

Any algorithm that can be coded with recursion can also be coded with an iterative structure.

True

Like a loop, a recursive function must have some method to control the number of times it repeats.

True

Recursive algorithms are less efficient than iterative algorithms

True

The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer a strong argument against it.

True

To solve a problem recursively, you must identify at least one case in which the problem can be solved without recursion.

True

When a recursive function directly calls itself, this is known as direct recursion.

True

The programmer must ensure that a recursive function does NOT become

an endless loop

When function A calls function B which, in turn, calls function A, this is known as

indirect recursion

The QuickSort algorithm is used to sort

lists stored in arrays or linear linked lists

The QuickSort algorithm is used to sort ________.

lists stored in arrays or linear linked lists

A ________ function is one that calls itself.

recursive

The QuickSort algorithm works on the basis of

two sublists and a pivot

If a recursive algorithm does NOT contain a base case, it

uses up all available stack memory, causing the program to crash

The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is

zero

How many times will the following function call itself if 5 is passed as the argument? void showMessage(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n + 1); } }

An infinite number of times

The QuickSort algorithm was developed in 1960 by

C.A.R. Hoare

A recursive function cannot call another function.

False

All mathematical problems are designed to be more efficient using recursive solutions.

False

In a recursive solution, the base case is always the first case to be called.

False

Indirect recursion means that a function calls itself n number of times and then processing of the function starts from the first call.

False

The ________ algorithm uses recursion to sort a list.

QuickSort

A recursive function is designed to terminate when it reaches its

base case

The following code is an example of a ________ recursive algorithm. int myRecursion (int array[], int first, int last, int val) { int num; if (first > last) return -1; num = (first + last) / 2; if (array[num] == val) return num; if (array[num] < val) return myRecursion(array, num + 1, last, val); else return myRecursion(array, first, num - 1, val); }

binary search

Select all that apply. Which of the following problems can be solved using recursion?

computing factorials finding the greatest common divisor of two numbers doing a Binary Search

The ________ of recursion is the number of times a recursive function calls itself.

depth


संबंधित स्टडी सेट्स

Chapter 2 - Extra Bank Questions

View Set

Chapter 3: Stress -- Its Meaning, Impact & Sources

View Set

Economic Growth, Capital, Interest, Growth Rates and Discounting

View Set

PN NCLEX Evolve Medication/IV calculations

View Set

bruh world studies heres da study guide!!!!!!!!!!!!

View Set