Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multiple Choice Multiple Choice Section 8.1 Recursive Methods In a single method

ID: 3537361 • Letter: M

Question

Multiple Choice

Multiple Choice
Section 8.1
Recursive Methods In a single method declaration, what is the maximum number of statements that may be recursive calls?A. 1B. 2C. n (where n is the argument)D. There is no fixed maximumWhat is the maximum depth of recursive calls a method may make?A. 1B. 2C. n (where n is the argument)D. There is no fixed maximumConsider the following method: void superWriteVertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. { if (number < 0) { System.out.println("-"); superWriteVertical(-number); } else if (number < 10) System.out.println(number); else { superWriteVertical(number / 10); System.out.println(number % 10); } } What values of number are directly handled by the stopping case?A. number < 0B. number < 10C. number >= 0 && number < 10D. number > 10Consider the following method: void superWriteVertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. { if (number < 0) { System.out.println("-"); superWriteVertical(-number); } else if (number < 10) System.out.println(number); else { superWriteVertical(number / 10); System.out.println(number % 10); } } Which call will result in the most recursive calls?A. super_write_vertical(-1023)B. super_write_vertical(0)C. super_write_vertical(100)D. super_write_vertical(1023)Consider this method declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } System.out.print("*"); } How many asterisks are printed by the method call quiz(5)?A. 3B. 4C. 7D. 8E. Some other numberThis question is appropriate if you studied a flood fill (which was not part of the text). Suppose that a flood fill starts at the point marked with an o in this diagram: XXXXXXXXXX XX XXXX This is row number 1 XX XX XXXX This is row number 2 XX o XXX This is row number 3 XXXXXXXXXX Suppose that the first recursive call is always left; the second recursive call is always right; the third recursive call is always up; the fourth recursive call is always down. How will the rows be completely filled?A. Row 1 is filled first, then row 2, then row 3B. Row 1 is filled first, then row 3, then row 2C. Row 2 is filled first, then row 3, then row 1D. Row 3 is filled first, then row 1, then row 2E. Row 3 is filled first, then row 2, then row 1In a real computer, what will happen if you make a recursive call without making the problem smaller?A. The operating system detects the infinite recursion because of the "repeated state"B. The program keeps running until you press Ctrl-CC. The results are nondeterministicD. The run-time stack overflows, halting the programWhen the compiler compiles your program, how is a recursive call treated differently than a non-recursive method call?A. Primitive values are all treated as reference variablesB. Reference variables are all treated as primitive valuesC. There is no duplication of local variablesD. None of the aboveWhen a method call is executed, which information is not saved in the activation record?A. Current depth of recursion.B. Formal parameters.C. Location where the method should return when done.D. Local variables.Consider the following method: public static void test_a(int n) { System.out.println(n + " "); if (n>0) test_a(n-2); } What is printed by the call test_a(4)?A. 0 2 4B. 0 2C. 2 4D. 4 2E. 4 2 0Consider the following method: public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); } What is printed by the call test_b(4)?A. 0 2 4B. 0 2C. 2 4D. 4 2E. 4 2 0Multiple Choice Section 8.2 Fractals and MazesSuppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum number of calls to traverse_maze that can be generated if you start at the entrance and call traverse_maze?A. 10B. 20C. 30D. 200Suppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum depth of recursion that can result if you start at the entrance and call traverse_maze?A. 10B. 20C. 30D. 200What is the relationship between the maximum depth of recursion for traverse_maze and the length of an actual path found from the entrance to the tapestry?A. The maximum depth is always less than or equal to the path length.B. The maximum depth is always equal to the path length.C. The maximum depth is always greater than or equal to the path length.D. None of the above relationships are always true.Multiple Choice Section 8.3 Reasoning about RecursionWhat would a suitable variant expression be for the traverse_maze method which could be used to prove termination? Assume N is the number of rows in the maze and M is the number of columns.A. N + MB. N + M + 1C. N * MD. The number of unexplored spaces in the maze.What technique is often used to prove the correctness of a recursive method?A. Communitivity.B. Diagonalization.C. Mathematical induction.D. Matrix Multiplication. Multiple Choice
Section 8.1
Recursive Methods

Explanation / Answer

1)

Hence the correct option is D. There is no fixed maximum.

2)

Hence the correct option is D. There is no fixed maximum

3)

else if (number < 10)

                        cout<<number<<endl;

Hence the correct option is C. number >= 0 && number < 10

4)

Observe the following recursive calls.

Obviously, superWriteVertical(-1023)results more recursive calls.

Hence the correct option is A. superWriteVertical(-1023)

5)

Hence the correct option is C.7 .

6)

When the flood fill starts in a cell,

Hence the correct option is A. Row 1 is filled first, then row 2, then row 3.

7)

Hence the correct option is D. The run-time stack overflows, halting the program

8)

Hence the correct option is D. None of the above

9)

Hence the correct option is A. Current depth of recursion.

10)

16)

Hence the correct option is C. Mathematical induction.