Exam 15: Recursion

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

  -Consider the accompanying definition of a recursive function.Which of the statements represent the base case? -Consider the accompanying definition of a recursive function.Which of the statements represent the base case?

(Multiple Choice)
4.8/5
(71)

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

(Multiple Choice)
4.9/5
(66)

The language of a computer,called ____________________ language,is a series of 0s and 1s.

(Short Answer)
4.9/5
(87)

Consider the following definition of the recursive function print. void print(int num) { \quad If (num > 0) \quad { \quad\quad Cout << num << " "; \quad\quad Print(num - 1); \quad } } What is the output of the following statement? Print(4);

(Multiple Choice)
5.0/5
(85)

int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else //Line 5 return n + foo(n - 1); //Line 6 } //Line 7 -Consider the accompanying definition of a recursive function.Which of the statements represent the general case?

(Multiple Choice)
4.8/5
(86)

The fourth Fibonacci number in a sequence is the sum of the ____________________ Fibonacci numbers.

(Short Answer)
4.8/5
(80)

The ____ case is the case for which the solution is obtained directly.

(Multiple Choice)
4.8/5
(81)

The numbering system that the computer uses is called the ____________________ system.

(Short Answer)
4.9/5
(78)

int puzzle(int start, int end) { if (start > end) \quad return start - end; else if (start == end) \quad return start + end; else \quad 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;

(Multiple Choice)
4.7/5
(81)

____ control structures use a looping structure,such as while,for,or do...while,to repeat a set of statements.

(Multiple Choice)
4.7/5
(79)

int recFunc(int num) { \quad if (num >= 10) \quad\quad return 10; \quad else \quad\quad return num * recFunc(num + 1); } -Tracing through ____ recursion is more tedious than tracing other recursive forms.

(Multiple Choice)
4.9/5
(80)

int mystery(int list[ ], int first, int last) { \quad if (first == last) \quad\quad return list[first]; \quad else \quad\quad 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;

(Multiple Choice)
4.8/5
(69)

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

(Multiple Choice)
4.9/5
(70)

Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters.

(True/False)
4.9/5
(80)

Consider the following code. int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } The function fact is an example of a(n)____________________ recursive function.

(Short Answer)
4.8/5
(71)

The collating sequence of A in the ASCII character set is ____________________.

(Short Answer)
4.9/5
(74)

If you execute a(n)____________________ recursive function on a computer,the function executes until the system runs out of memory.

(Short Answer)
4.8/5
(76)

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

(True/False)
4.7/5
(69)

int recFunc(int num) { \quad if (num >= 10) \quad\quad return 10; \quad else \quad\quad return num * recFunc(num + 1); } -A function is called ____ if it calls itself.

(Multiple Choice)
4.9/5
(82)

int recFunc(int num) { \quad if (num >= 10) \quad\quad return 10; \quad else \quad\quad return num * recFunc(num + 1); } -Consider the accompanying definition of a recursive function.What is the output of the following statement? cout << recFunc(10)<< endl;

(Multiple Choice)
4.8/5
(82)
Showing 21 - 40 of 50
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)