Java 2 Final Recursion

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

10) All recursive programs ____________________________________ . a) are more difficult to read than iterative programs. b) can be implemented iteratively. c) are easier to read than iterative programs. d) are shorter than iterative programs. e) none of the above are true.

b) can be implemented iteratively.

4) The _______________________ puzzle is a favorite of computer scientists because of its elegant recursive solution. a) Tower of Hanoi b) Sudoku c) Tetris d) Tic-Tac-Toe e) none of the above

a) Tower of Hanoi

11) The recursive solution of the Towers of Hanoi problem has _______________ complexity. a) exponential b) polynomial c) logarithmic d) low e) none of the above

a) exponential

14) A solution with exponential complexity is ____________________ . a) efficient b) inefficient c) easy to implement d) difficult to implement e) none of the above

b) inefficient

13) There is(are) ____________ base case(s) in the recursive solution to finding a path through a maze. a) 0 b) 1 c) 2 d) 3 e) 4

c) 2

3) __________________ recursion results from the lack of a base case. a) Indirect b) Direct c) Infinite d) Spiral e) none of the above

c) Infinite

7) Which of the following statements is true? a) Recursion should be used in every program. b) Recursion should be avoided all the time. c) Solutions that are easily expressed recursively should be programmed recursively. d) Solutions that are easily expressed recursively should be programmed iteratively. e) None of the above.

c) Solutions that are easily expressed recursively should be programmed recursively.

2) ____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method. a) upward, downward b) downward, upward c) direct, indirect d) indirect, direct e) none of the above

c) direct, indirect

12) Which of the following is a proper recursive definition of x raised to the y power? a) x^y = x*x^y-1 b)x^y = x*x^y-2 c)x^y = x*x^y-1 for y>1: x^y = x for y = 1 d) x^y = x*x^y-1 for all x e) none of the above

c)x^y = x*x^y-1 for y>1: x^y = x for y = 1

5) In the Towers of Hanoi puzzle, there are ________________ pegs. a) 2 b) 3 c) 4 d) 5 e) The Towers of Hanoi puzzle can include any number of pegs

b) 3

9) How many base cases must a recursive method have? a) A recursive method does not have to have a base case. b) at least 1 c) more than 1 d) more than 2 e) more than 3

b) at least 1

10) Recursive solutions are always more efficient than iterative solutions

Answer: False

2) Some problems can only be solved recursively.

Answer: False

5) Recursive solutions to problems should be used whenever possible.

Answer: False

6) In the Towers of Hanoi puzzle, it is legal to move a larger disk to a peg that already contains a smaller disk.

Answer: False

7) The Towers of Hanoi puzzle cannot be solved iteratively.

Answer: False

9) A program with infinite recursion will act similarly to a program with an infinite loop.

Answer: False

1) In Java, it is possible for a method to call itself.

Answer: True

3) All recursive methods must have a base case.

Answer: True

4) A method that calls a different method, which then calls the original calling method is a recursive method.

Answer: True

8) Determining whether or not there is a path through a maze has a recursive solution

Answer: True

8) Which of the following will result from infinite recursion in Java? a) The program will hang as though there is an infinite loop. b) The program will throw an ArrayOutOfBoundsException. c) The program will not compile. d) The program will run out of memory. e) none of the above.

d) The program will run out of memory.

15) In a recursive solution, _______________ is(are) always necessary. a) short, efficient code b) several variables c) numerous lines of code d) a base case e) none of the above

d) a base case

1) A method that calls itself is a __________________ method. a) invalid b) static c) final d) recursive e) public

d) recursive

6) In indirect recursion, how many method calls can occur between one call to a method and the next one that completes the indirect recursion a) 2 b) 3 c) 4 d) 5 e) There is no limit to the number of intervening calls between a method and its indirect recursive call.

e) There is no limit to the number of intervening calls between a method and its indirect recursive call.


Ensembles d'études connexes

AP Environmental Science Unit 1 - Environmental History & Sustainability

View Set

Chapter 34: Assessment and Management of Patients with Inflammatory Rheumatic Disorders

View Set

MANGMT 3540: Final Exam Study Guide

View Set

CH.4 Individual Income Tax Overview, Dependents, and Filing Status

View Set

4510: Concept Synthesis, Exam 1 - Oxygenation, Perfusion, Elimination, Fluid and Electrolyte, Infection

View Set

HEART EKG DYSRYTHMIAS HEART BLOCK PACEMAKER

View Set

Practice Reading Chemical Formulas

View Set