Java Reference
In-Depth Information
int count = wordCountMap.get(word);
if (count > OCCURRENCES) {
reverseMap.put(count, word);
}
}
// print the words sorted by count
for (int count : reverseMap.keySet()) {
String word = reverseMap.get(count);
System.out.println(word + " occurs " + count + " times.");
}
}
Chapter 12
1. Recursion is a technique that expresses an algorithm in terms of itself. A recursive
method differs from a regular method in that it contains one or more calls to itself
within its body.
2. A base case is a situation in which a recursive method does not need to make a
recursive call to solve the problem. A recursive case is a situation in which the
recursive method does call itself. Recursive methods need both cases because the
recursive case is called repeatedly until the base case is reached, stopping the chain
of recursive calls.
3. (a) 1
(b) 1, 2
(c) 1, 3
(d) 1, 2, 4
(e) 1, 2, 4, 8, 16
(f) 1, 3, 7, 15, 30
(g) 1, 3, 6, 12, 25, 50, 100
4. (a) 113
(b) 140, 70
(c) 168, 84, 42
(d) 120, 60, 30
(e) 160, 80, 40, 20, 10
5. (a) *
(b) [*]
(c) ([*])
(d) ([([*])])
(e) [([([*])])]
 
Search WWH ::




Custom Search