Ch14 Full Test Bank - Problem Solving With Recursion - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 14 - Problem Solving with Recursion
True/False (10)
- The Towers of Hanoi problem cannot be solved iteratively.
- Computing the nth Fibonacci number is more efficient with iteration than with recursion.
- The first rule of the Tower of Hanoi problem states that each disk you move must be a bottom-most disk.
- The solution to the Towers of Hanoi is O(2n).
- The definition of an identifier includes the word identifier.
- An expression such as a + b c is called infix notation.
- The expression a + b c written in postfix notation is a b + c
- An iterative solution to the Towers of Hanoi problem moves fewer disks than the recursive solution.
- The n-queens problem requires an n x n chessboard and uses the rules of chess to create a solution.
- The rules of a language are called its grammar.
Short Answer (8)
- Explain why the recursive Fibonacci program is so inefficient.
- Provide the algorithm for the recursive solution to compute the nth Fibonacci number.
Algorithm Fibonacci (n)
if (n <= 1)
return 1
else
return Fibonacci(n-1) + Fibonacci(n-2)
- Provide the Java code for the iterative solution to compute the nth Fibonacci number.
static int IterFibonacci (int n)
{
int previous = 0;
int next = 1;
int result = 0;
for (int i = 0; i < n; i++)
{
result = previous + next;
previous = next;
next = result;
}
return result;
}
- List the three rules for the Tower of Hanoi problem.
1. Move one disk at a time. Each disk you move must be a topmost disk.
2. No disk may rest on top of a disk smaller than itself.
3. You can store disks on the second pole temporarily, as long as you observe rules 1 and 2.
- Convert the following to postfix: a + b c / d
- Convert the following to infix: a b c d / +
- Convert the following to prefix: (a + b) c
- Assume a = 2; b = 3; c = 18; and d = 9.
What is the value of the following postfix expression: a b + c d / -
Multiple Choice (22) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- The solution to the Towers of Hanoi starting with three poles requires
- 7 moves
- 3 moves
- 6 moves
- 9 moves
- The solution to the Towers of Hanoi problem
- grows exponentially
- grows linearly
- grows quadratically
- is independent of the number of discs
- The solution to the Towers of Hanoi problem with n discs requires
- 2n – 1 moves
- 2n moves
- 2n + 1 moves
- n2 -1 moves
- The solution to the Towers of Hanoi problem with 20 discs requires approximately
- 1,000,000 moves
- 1,000 moves
- 10,000 moves
- 1,000,000,000 moves
- A Java identifier can be defined by the rule
- <identifier> = <letter> |<identifier><letter> | <identifier><digit>
- <identifier> = <digit><digit><letter> | <identifier><letter> | <identifier><digit>
- <identifier> = <digit><letter><identifier> | <letter><letter> | <identifier><digit>
- all of the above
- A special case of indirect recursion, where Method A calls Method B, and Method B calls Method A, is called ____.
- mutual recursion
- infinite recursion
- backtrack recursion
- all of the above
- A(n) ____ allows you to check whether a given string is in a language.
- recognition algorithm
- prefix expression
- exhaustive search
- indirect recursion algorithm
- A(n) ____ technique checks all possible choices for a solution.
- brute-force
- mutual recursion
- indirect recursion
- exhaustive recursion
- Identify the prefix version of this infix expression: A B + C D
- + a b c d
- + a b c d
- + a b + c d
- + a b c d
- Identify the postfix version of this infix expression: (a + b) (c / d)
- a b + c / d
- a b c d + /
- a b + c d /
- c d / a b +
- What is the value of the following postfix expression: a b c + d –
Assume a = 10, b = 6, c = 2, and d = 5
- 17
- -7
- 125
- None of the above.
- What is the value of the following postfix expression: a b - c d / +
Assume a = 10, b = 6, c = 12, and d = 2
- 10
- 6
- 12
- The answer cannot be determined
- What is the value of the following postfix expression: a b - c - d / +
Assume a = 10, b = 6, c = 12, and d = 2
- 10
- 6
- 12
- The answer cannot be determined
- Provide the missing line of pseudocode:
isIdentifier(s: string): boolean
{
if (s is of length 1) // Base case
{
if (s is a letter)
return true
else
return false
}
else if (the last character of s is a letter or a digit)
//Provide this line of code
else
return false
}
- return isIdentifier(s minus its last character)
- return isIdentifier(s)
- return s minus its last character
- None of the above
- Convert the following prefix expression to infix: - a + b c / - d e + - f g h
- (a-b+c) (d-e) / (f-g+h)
- (a+b-c) (d+e) / (f-g-h)
- (a-b+c) (d/e) - (f-g+h)
- The expression cannot be converted
- Convert the following prefix expression to infix: / - a b + - c d e
- ( (a-b) / ( (c-d) + e) )
- ( (a+b) / ( (c+d) + e) )
- ( (a/b) - ( (c+d) - e) )
- The expression cannot be converted
- The efficiency for solving the Towers of Hanoi problem recursively is
- O(2n)
- O(n2)
- O(n)
- O(log n)
- The rate of growth for the Towers of Hanoi problem as the number of disks increases is
- exponential
- quadratic
- linear
- constant
- What is the value of this postfix expression: 1 2 3 4 + 5
- 70
- 19
- 15
- This is not a valid postfix expression
- Convert the following infix expression to postfix: x ^ y / (5 z) + 10
- x y ^ 5 z / 10 +
- y x ^ 5 z 10 / +
- x y 5 z ^ / 10 +
- x y z 5 ^ / 10 +
- Convert the following infix expression to postfix: ( (8-2) (7+3) ) ^ 2
- 8 2 – 7 3 + 2 ^
- 8 2 ^ 7 3 + 2 -
- 2 ^ 8 2 – 7 3 + +
- 8 2 – 7 3 + 2 ^
- What is the value of this postfix expression: 1 2 3 + 4 + 5
- 70
- 19
- 15
- This is not a valid postfix expression
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano