22.4. The Comparator Interface

 
[Page 650 ( continued )]

Review Questions

Sections 19.1 “19.3

19.1 What is a recursive method? Describe the characteristics of recursive methods . What is an infinite recursion?
19.2 Write a recursive mathematical definition for computing 2 n for a positive integer n .
19.3 Write a recursive mathematical definition for computing x n for a positive integer n and a real number x .
19.4 Write a recursive mathematical definition for computing 1 + 2 + 3 + ... + n for a positive integer n .
19.5 How many times is the factorial method in Listing 19.1 invoked for factorial(6) ?
19.6 How many times is the fib method in Listing 19.2 invoked for fib(6) ?
19.7 Show the output of the following program:

[Page 651]
19.8 Show the output of the following two programs:
19.9 What is wrong in the following method?

Sections 19.4 “19.6

19.10 Show the call stack for isPalindrome("abcba") using the methods declared in Listing 19.3 and Listing 19.4, respectively.
19.11 Show the call stack for selectionSort(new double[]{2, 3, 5, 1}) using the method declared in Listing 19.5.
19.12 What is a recursive helper method?

Section 19.6 Towers of Hanoi

19.13 How many times is the moveDisks method in Listing 19.7 invoked for move-Disks(5, 'A', 'B', 'C') ?

Section 19.8 Recursion versus Iteration

19.14 Which of the following statements are true?
  • Any recursive method can be converted into a non-recursive method.

  • Recursive methods take more time and memory to execute than non-recursive methods.

  • Recursive methods are always simpler than non-recursive methods.

  • There is always a condition statement in a recursive method to check whether a base case is reached.

19.15 What is the cause for the stack overflow exception?
 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net