
CS 220 – Programming with Data Structures – Fall 2009
Homework #3
(not being collected, for exam review)
1. Text Chapter 10, Exercise No. 11.
Methods should take at least one argument, a Node<T> at which you start counting,
e.g., the first/head Node in a linked list.
Do three versions:
(A) Tail recursive version (the recursive calls do not return values, so you pass along
additional argument(s));
(B) Non-tail recursive version (the recusive method returns the count for the remainder
of the list, which is used to compute the count including the current Node).
(C) Iterative version.
2. Text Chapter 10, Exercise No. 16.
The signature for the top-level method should be:
public static int minimum(int[] data)
Then use a “helper method” that does the actual recursion, and has additional param-
eters, which change as you recurse.
(Hint: you approach should use a divide-and-conquer approach, similar to that used
for merge sort in Chapter 12.)
3. Text Chapter 10, Exercise No. 17.
4. Text Chapter 21, Exercise No. 2.
5. Text Chapter 21, Exercise No. 3.
6. Text Chapter 21, Exercise No. 11.
Instead of just code, write methods to do this, assuming the stack argument will be of
type LinkedStack<T>.
Do two methods using different approaches:
(A) An iterative version (this will require that you use a stack in your code, which can
be either the text’s LinkedStack<T> or Java’s Stack<T>);
(B) A recusive version (this approach will not require a stack data object, as Java’s
stack frames for the recursive calls can serve as the stack).
7. Text Chapter 22, Exercise No. 2.
8. Text Chapter 23, Exercise No. 3.
9. Text Chapter 23, Exercise No. 4.
10. Text Chapter 23, Exercise No. 5.