Java Software Structures, 4th Edition Exercise Solutions, Ch. 13
Chapter 13 Exercise Solutions
EX 13.1 Define the concept of a set. List additional operations that might be considered for a set.
A set is a collection of elements with no duplicates. Generally, the elements in sets have
EX 13.2 The TreeSet class is built upon a backing instance of the TreeMap class. Discuss the
advantages and disadvantages of this strategy for reuse.
By using a TreeMap to implement the TreeSet class, much of the common functionality
EX 13.3 Given the nature of a set, one could implement the Set interface using any one of a
variety of other collections or data structures. Describe how you might implement the
Set interface using a LinkedList. Discuss the advantages and disadvantages of this
approach.
A LinkedList would be a fairly straightforward implementation, although not particularly
EX 13.4 A bag is a very similar construct to a set except that duplicates are allowed in a bag.
What changes would have to be made to extend a TreeSet to create an implementation
of a bag?
The primary change would be to remove the duplicate restriction in the add method.
Since the addAll method, and then indirectly the union method, use the add method, this
EX 13.5 Draw a UML diagram showing the relationships among the classes involved in the
Product Sales example from this chapter.
EX 13.6 Draw a UML diagram showing the relationships among the classes involved in the User
Management example from this chapter.
EX 13.7 Describe two hashing functions that might be appropriate for a data set organized by
name (e.g. last name, first name, middle initial).
Java Software Structures, 4th Edition Exercise Solutions, Ch. 13
The answer to this exercise is currently not provided.
EX 13.8 Explain when it might be preferable to use a map instead of a set.
Maps are particularly helpful for relating keys and values, whereas sets focus on