Homework 5
Due Date: Nov 25, 2014
Note: This homework is worth twice as much as any other.
This assignment is to for you to solve two problems that appeared
in the ACM International Intercollegiate Programming Contest,
North Central North America Regional.
The first problem is called Nested Boxes and is available
here.
The second problem is called Spectrum and is available
here.
Each problem requires implementing a graph data structure
and a graph algorithm.
Write your programs in Java.
The following points are worth mentioning.
-
Your programs read from standard input and write to standard output.
In terms of programming in Java, this means you should use the
Scanner class.
You can use an IDE like eclipse to develop your programs.
Doing so allows you to utilize the IDE's editor, source-code highlighting,
and debugging facility.
But you should run your programs from the command line.
Do not make your programs read from or write to a file,
or hardcoding test data in your programs.
-
For the Nested Box problem, you should write a (directed) graph class.
Use a graph algorithm we studied in class to solve the problem.
I am not telling which algorithm. You have to find out on your own.
-
For the Spectrum problem you should write a graph class
with methods for
add
ing a vertex, add
ing an edge,
returning connections
,
and answering the associated
question.
But these methods alone are not enough.
You need to implement some graph algorithm that we learn in class.
Again you have to find out on your own the appropriate algorithm to use.
An important decision you have to make is how to represent graphs.
Choosing the wrong data structures for graph representation
can make your work more difficult than it ought to be.
-
Make sure your programs' output is exactly as described in the
problem statements.
When testing, you should make up your own input for which you know
the correct output.
-
You can work on this assignment as a team of at most 3 people.
Each team should submit only two programs with the statement
"Each of us contributed equally," with all members signing.
Submit the source code of your programs and a README
file
by emailing them to me.