C++ Chapter 15

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

In the Tower of Hanoi recursive program, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is 8.

False

Which of the following solutions is easier to construct for the Tower of Hanoi problem?

Recursive

The ____ case is the case for which the solution to an equation is obtained directly.

base

A recursive function in which the last statement executed is the recursive call is called a(n) ____ recursive function.

tail

int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9}; what is the output of the following statement? cout << mystery(alpha, 0, 4) << endl;

27

int puzzle(int start, int end) { if (start > end) return start - end; else if (start == end) return start + end; else return end * puzzle(start + 1, end - 1); } Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(3, 7) << endl;

42

Consider the following definition of the recursive function mystery. int mystery(int num) { if (num <= 0) return 0; else if (num % 2 == 0) return num + mystery(num - 1); else return num * mystery(num - 1); } What is the output of the following statement? cout << mystery(5) << endl;

50

int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Consider the accompanying definition of the recursive function mystery. Given the declaration: int beta[10] = {2, 5, 8, 9, 13, 15, 18, 20, 23, 25}; What is the output of the following statement? cout << mystery(beta, 4, 7) << endl;

66

int puzzle(int start, int end) { if (start > end) return start - end; else if (start == end) return start + end; else return end * puzzle(start + 1, end - 1); } Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(5, 10) << endl;

720

The following is an example of a recursive function, where nextNum is a function such that nextNum(x) = x + 1. int recFunc(int x) { return nextNum(nextNum(x)); }

False

Which of the following solution methods would be the best choice for a mission control system?

Iterative

void printNum(int num) //Line 1 { //Line 2 if (n < 0) //Line 3 cout << "Num is negative" << endl; //Line 4 else if (num == 0) //Line 5 cout << "Num is zero" << endl; //Line 6 else //Line 7 { //Line 8 cout << num << " "; //Line 9 printNum(num - 1); //Line 10 } //Line 11 } //Line 12 Consider the accompanying definition of a recursive function. Which of the statements represent the base case?

Statements in Lines 3-6

In a recursive function, the base case stops the recursion.

True

The following is a valid recursive definition to determine the factorial of a non-negative integer. 0! = 1 1! = 1 n! = n * (n - 1)! if n > 0

True

The following is an example of a recursive function. void print(int x) { if (x > 0) { cout << x << " " ; print (x - 1); } }

True

To design a recursive function, you must determine the limiting conditions.

True

You can use a recursive algorithm to find the largest element in an array.

True

A function is called ____ if it calls itself.

directly recursive

Which of the following function headings can be used for a recursive definition of a function to calculate the nth Fibonacci number?

int rFibNum(int a, int b, int n)

A definition in which something is defined in terms of a smaller version of itself is called a(n) ____ definition.

recursive


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

OSHA 3- Struck and Caught Hazards

View Set

Testing a Claim about a Difference between Proportions assignment

View Set

3.2 Conditional Probability & Multiplication Rule

View Set

Med-Surge Nursing Shock Prep U ch. 14

View Set

Life Insurance Practice Questions (chapter 4)

View Set

Anthropology 101 2002 CSN Essentials of Cultural Anthropology Chapter 9

View Set

Principles of Management (Chapter 2)

View Set

Managing Operations Multiple Choice

View Set