Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. Every recursive definition must have one or more base cases. b. Every recursive function must have one or more base cases. c. The general case stops the recursion. d. In the general case, the solution to the problem is obtained directly. e. A recursive function always returns a value.

Problem 3

What is a recursive case?

Problem 4

What is direct recursion?

Problem 5

What is indirect recursion?

Problem 6

What is tail recursion?

Problem 7

Consider the following recursive function: int mystery(int number) //Line 1 { if (number == 0) //Line 2 return number; //Line 3 else //Line 4 return(number + mystery(number – 1)); //Line 5 } a. Identify the base case. b. Identify the general case. c. What valid values can be passed as parameters to the function mystery? d. If mystery(0) is a valid call, what is its value? If not, explain why. e. If mystery(5) is a valid call, what is its value? If not, explain why. f. If mystery(-3) is a valid call, what is its value? If not, explain why.

Problem 8

Consider the following recursive function: void funcRec(int u, char v) //Line 1 { if (u == 0) //Line 2 cout << v; //Line 3 else if (u == 1) //Line 4 cout << static_cast (static_cast(v) + 1); //Line 5 else //Line 6 funcRec(u - 1, v); //Line 7 } Answer the following questions: a. Identify the base case. b. Identify the general case. c. What is the output of the following statement? funcRec(5, 'A');

Problem 9

Consider the following recursive function: void recFun(int x) { if (x > 10) { recFun(x / 10); cout << x % 10 << endl; } else cout << x << endl; } What is the output of the following statements? a. recFun(258); b. recFun(7); c. recFun(36); d. recFun(-85);

Problem 10

Consider the following recursive function: void recFun(int u) { if (u == 1) cout << "Stop! "; else { cout << "Go "; recFun(u - 1);; } } What is the output, if any, of the following statements? a. recFun(7); b. recFun(3); c. recFun(-6);

Problem 11

Consider the following recursive function: void exercise(int x) { if (x > 0 && x < 10) { cout << x << " "; exercise(x + 1); } } What is the output of the following statements? a. exercise(0); b. exercise(5); c. exercise(10); d. exercise(-5);

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks