Programming Languages Chapter 18 can be called indirectly through another method

subject Type Homework Help
subject Pages 4
subject Words 883
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 18: Recursion
18.1 Introduction
18.1 Q1: A recursive method .
a. is a method that calls itself.
b. can be called directly.
c. can be called indirectly through another method.
d. All of the above.
18.2 Recursion Concepts
18.2 Q1: When a recursive method is called to solve a problem, the method actually is
capable of solving only the simplest case(s), or .
a. base case(s).
b. base step(s).
c. recursive call(s).
d. recursion step(s).
18.2 Q2: When the recursion step executes:
a. this is known as indirect recursion.
b. all of the computer’s processes halt until the recursion step has completed executing.
c. the original call to the method is still active.
d. All of the above.
18.3 Example Using Recursion: Factorials
18.3 Q1: Which of the following statements about recursion are true?
a. Recursion can occur infinitely.
b. Recursion uses a termination test.
c. Both a and b.
d. Neither a nor b.
18.3 Q2: The recursion step should:
a. check for the base case.
b. call a fresh copy of the recursive method to work on a smaller problem.
c. make two calls to the recursive method.
d. iterate until it reaches a termination condition.
page-pf2
18.4 Reimplementing Class FactorialCalculator
18.4 Q1: Which of the following is false?
a. Since BigInteger is not a primitive type, we can’t use the arithmetic, relational and
equality operators with BigIntegers.
b. BigInteger method compareTo compares the BigInteger number that calls the
method to the method’s BigInteger argument, and returns -1 if the BigInteger that
calls the method is less than the argument, 0 if they’re equal or 1 if the BigInteger that
calls the method is greater than the argument.
c. The value 1 can be implicitly converted to a BigInteger.
d. BigInteger can represent integer values larger than what primitive type long can
represent.
18.5 Example Using Recursion: Fibonacci Series
18.5 Q1: The number of calls to recursively calculate the Fibonacci value of 7 is:
a. 7
b. 13
c. 41
d. 39
18.5 Q2: The operands of an operator are evaluated ________.
a. from right to left.
b. from left to right.
c. at the same time.
d. in an order that is specific to each operator.
18.6 Recursion and the Method Call Stack
18.6 Q1: The current method executing is always the method whose activation record is
________.
a. at the bottom of the stack.
b. at the top of the stack.
c. never placed on the stack.
page-pf3
d. second from the top of the stack, just below the previous method call.
18.7 Recursion vs. Iteration
18.7 Q1: Recursion is often less efficient than iteration because ________.
a. it can cause an explosion of method calls.
b. it is not as intuitive.
c. recursive methods are harder to debug.
d. recursive methods take longer to program.
18.7 Q2: All of the following are true for both recursion and iteration except ________.
a. they have a base case.
b. they can cause infinite loops or infinite recursion.
c. they are based on a control statement.
d. both gradually approach termination.
18.7 Q3: Recursion often is preferable to iteration because ________.
a. it is faster.
b. it requires less memory.
c. it models the problem more logically.
d. All of the above.
18.8 Towers of Hanoi
18.9 Fractals
18.9 Q1: Fractals that yield an exact copy of the original when a portion of the original
image is magnified are called fractals.
a. strictly self-similar.
b. Koch Curve.
c. similar.
d. mirror.
18.9.1 Koch Curve Fractal
18.9.1 Q1: Each time a fractal’s pattern is applied to it, the fractal is said to be at a new
________.
page-pf4
a. level.
b. depth.
c. order.
d. All of the above.
18.9.2 (Optional) Case Study: Lo Feather Fractal
18.9.2 Q1: After a fractal’s pattern is applied several times, the shape of the fractal will
generally become ________.
a. disjointed and less detailed.
b. stabilized and more detailed.
c. identical to the original fractal.
d. None of the above.
18.10 Q1: In recursive backtracking, if one set of recursive calls does not result in a
solution to the problem, what happens?
a. The program returns to a previous decision point and makes a different decision.
b. The program backs up to the previous decision point and throws an exception.
c. The program continues, with unexpected results.
d. The program backs up to the original method call.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.