Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

ch2 True/False Indicate whether the statement is true or false. ____

1. Recursion is a repetitive process in which an algorithm calls itself.

____

2. The general case for the factorial recursive algorithm is: n * factorial (n + 1).

____

3. Every recursive algorithm must have a base case.

____

4. Every recursive call must either solve a part of the problem or reduce the size of the problem.

____

5. In a recursive algorithm, the rest of the algorithm (the part that is not the base case) is known as the general case.

____

6. Recursion works best when the algorithm uses a data structure that naturally supports recursion.

____

7. An interactive user interface program is well suited for recursive programming.

____

8. A recursive solution to a problem is advisable, even when the equivalent iterative solution runs much faster.

____

9. A nonrecursive algorithm generally runs more slowly than its recursive implementation.

____ 10. If the recursion is deep we may run out of memory. ____ 11. All looping algorithms can and should be implemented with recursion. ____ 12. It is advisable to write a recursive algorithm even if the recursive solution is longer and more complex than the iterative one. ____ 13. When the recursion occurs at the end of the function it is known as tail recursive. ____ 14. When the recursion occurs at the end of a function, an optimized compiler turns the recursive code into a simple loop, thus eliminating the function call inefficiency. ____ 15. Recursive solutions may involve extensive overhead (both time and memory) because they use calls. ____ 16. â€œ0, 1, 2, 3, 5, 8, 13, 21, 34â€? are the first few numbers of the Fibonacci series. ____ 17. A recursive solution to calculate Fibonacci numbers is efficient even for large numbers. ____ 18. The basic format of the algebraic notation we usually employ in every day life is called prefix notation. ____ 19. In prefix notation, the operator comes after its two operands. ____ 20. Postfix notation is also known as reverse Polish notation (RPN).

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

____ 21. When converting from prefix to postfix, we begin parsing at the left and work right until we isolate one binary expression. ____ 22. A recursive solution is usually much harder to code than the iterative solution. ____ 23. The postfix representation of the prefix expression “-+*ABC/EF” is “AB*C+EF/-”. ____ 24. The Towers of Hanoi problem is best solved with a recursive algorithm. ____ 25. The base case of the Towers of Hanoi recursive algorithm is to move one disk from source to destination. Multiple Choice Identify the choice that best completes the statement or answers the question. ____ 26. What will be the value of n the third time recursive factorial is called? The original (first) call is “factorial(5)”. Algorithm recursiveFactorial (n) if (n equals 0) return 1 else return (n * recursiveFactorial (n - 1)) end if end recursiveFactorial a. 1 c. 3 b. 2 d. 4 ____ 27. What is the postcondition of the following recursive algorithm? Algorithm recursiveAlgorithm (n) if (n equals 0) return 1 else return (n * recursiveAlgorithm (n - 1)) end if end recursiveAlgorithm a. n is returned c. n! is returned b. n^2 is returned d. sum(1..n) is returned ____ 28. In recursion, the statement that “solves” the problem is known as the _____. a. return statement c. recursive call b. base case d. recursive step ____ 29. The _____ contains the logic needed to reduce the size of the problem. a. parameter list c. base case b. return statement d. general case ____ 30. Every recursive call must either solve a part of the problem or _____. a. reduce the size of the problem b. increase the size of the problem c. call itself again d. check if a base case has been reached

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

____ 31. Which of the following problems is most suitable to be solved using recursion? a. binary search c. displaying a text menu to the user b. initializing an array with zeros (0) d. randomly shuffling a deck of cards ____ 32. As a general rule, recursive algorithms should be used only when their efficiency is _____. a. linear c. quadratic b. logarithmic d. exponential ____ 33. The recursion is said to be deep when _____. a. there are few recursive calls c. its efficiency is exponential b. its efficiency is quadratic d. there are many recursive calls ____ 34. _____ are naturally recursive structures. a. Trees b. Scalar data items

c. Abstract data types d. Arrays

____ 35. Consider the following algorithm that calculates greatest common divisor using the Euclidean algorithm: Algorithm gcd (a, b) Post greatest common divisor returned if (b equals 0) return a end if if (a equals 0) return b end if return gcd (b, a mod b) end gcd What should be its pre-condition? a. a and b are positive integers greater than 0 b. a and b are positive integers, and a > b c. a and b are positive integers, and a < b d. a and b are integers ____ 36. The following algorithm that calculates greatest common divisor using the Euclidean algorithm has _____ base case(s). Algorithm gcd (a, b) Post greatest common divisor returned if (b equals 0) return a end if if (a equals 0) return b end if return gcd (b, a mod b) end gcd a. 0 c. 2 b. 1 d. 3 ____ 37. Consider the following function to calculate the nth Fibonacci number: long fib (long num) { if (num == 0 || num == 1)

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

return num; return (fib (num - 1) + fib (num - 2)); } What is(are) the base case(s)? a. 0 b. 1

c. 0 and 1 d. num - 1

____ 38. Consider the following function to calculate the nth Fibonacci number: long fib (long num) { if (num == 0 || num == 1) return num; return (fib (num - 1) + fib (num - 2)); } What line of code represents the general case? a. long fib (long num) b. if (num == 0 || num == 1) c. return num; d. return (fib (num - 1) + fib (num - 2)); ____ 39. The following function to calculate the nth Fibonacci number is inefficient because _____. long fib (long num) { if (num == 0 || num == 1) return num; return (fib (num - 1) + fib (num - 2)); } a. it tests both base cases in the same line b. it is tail recursive c. it does not check if num is negative d. it calculates each fib(n) twice: when called with fib(n+2) and when called with fib(n+1) ____ 40. In _____ notation the operator comes between the operands. a. prefix c. postfix b. infix d. rpn ____ 41. The expression â€œ*ABâ€? is in _____. a. prefix notation b. infix notation

c. postfix notation d. rpn

____ 42. In designing a recursive algorithm to convert prefix expressions to the postfix format, the base case is _____. a. finding an operator c. running out of characters b. finding an operand d. finding an end-of-line character ____ 43. From the recursive problems listed below, in which after each base case, do we return to a decomposition of the general case for several steps? a. nth Fibonacci number c. n! b. binary search d. Towers of Hanoi ____ 44. What does the following recursive algorithm do? Algorithm recursiveAlgorithm(n) if (n equals 0) return 0

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

end if return recursiveAlgorithm(n-1) end recursiveAlgorithm a. Returns the sum of the numbers from 1 to n b. Returns n! c. Returns n d. Returns 0 ____ 45. What is wrong with the following recursive algorithm? Algorithm recursiveAlgorithm(n) if (n equals 0) return 0 end if return n + recursiveAlgorithm(n) end recursiveAlgorithm a. It does not have a base case b. The general case does not reduce the size of the problem c. The base case should be 1 d. It should not have a base case ____ 46. What is wrong with the following recursive algorithm? Algorithm recursiveAlgorithm(n) if (n equals 0) return recursiveAlgorithm(1) end if return n + recursiveAlgorithm(n-1) end recursiveAlgorithm a. The base case calls the recursive algorithm b. The base case should be 1 c. The general case does not reduce the size of the problem d. It should not have a base case ____ 47. What is the 7th Fibonacci number? (Hint: the 0th is 0 and the 1st is 1) a. 5 c. 13 b. 8 d. 21 ____ 48. Consider the following function to calculate the nth Fibonacci number: long fib (long num) { if (num == 0 || num == 1) return num; return (fib (num - 1) + fib (num - 2)); } How many calls does it take to determine fib(4)? a. 5 c. 15 b. 9 d. 25 ____ 49. In designing a recursive algorithm to convert prefix expressions to the postfix format, the base case for the algorithm that determines the length of the prefix expression is _____. a. finding an operator c. running out of characters b. finding an operand d. finding an end of line character

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

____ 50. The solution for the Towers of Hanoi problem requires a recursive algorithm with four parameters: _____, the source needle, the destination needle, and the auxiliary needle. a. the position of the disk to move b. the number of times the recursion algorithm has been called c. the number of disks moved so far d. the number of disks to be moved

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

ch2 Answer Section TRUE/FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

T F T T T T F F F T F F T T T F F F F T T F T T T

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF:

47 49 49 49 49 50 50 50 50 50 50 50 50 50 50 54 57 57-58 58 58 59 65 63 65 67

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1 1 1

REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF:

48 47 49 49 49 50 50 50 50 53 53 56-57 56-57

MULTIPLE CHOICE 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

C C B D A A B D A A C C D

Full file at http://testbank360.eu/test-bank-data-structures-2nd-edition-gilberg

39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

D B A B D D B A C B B D

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1 1

REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: REF:

56-57 58 58 59 65 47-48 49 49 54 57 60 68