ICS 160E / ECE 144 - Algorithms Homework 4, 25 Points
Due: Friday, May 2, 2003
-
5 points.
Problem R-3.1 from Goodrich-Tamassia.
-
5 points.
Problem R-3.18 from Goodrich-Tamassia.
-
5 points.
Problem C-3.19 from Goodrich-Tamassia.
-
5 points.
Problem C-3.26 from Goodrich-Tamassia.
-
5 points.
Write a Java function, hasDuplicates(Integer[] a),
that uses the java.util.HashMap class to
determine whether or not
a given array of Integer objects contains two integers
of the same value. Your algorithm should
run in time roughly proportional to the size of the input array, a.
Turn in a listing of your program and its output for the following
arrays:
- { 1, 9, 3, 45, 12, 0, -9}
- { 1 }
- { 2, 4, 16, 128, 1024, 4}
- { 1, 1, 1, 5, 12, 0, -9}
- { 2, 4, 3, 5, 12, 0, 9}
Rule: This problem must be done independently. You cannot work with
someone else on problem 5!
Hint: study the class
java.util.HashMap.
You may also wish to look
at the class
java.lang.Integer.