Chapter 4 Greedy Algorithms - Programming Assignment
CS 343: Analysis of Algorithms,
Spring 2008
Suppose you have graduated from Willamette and are working for a Map company. The company needs a team of programmers to
figure out how to find the cheapest route from
between points on a map. Specifically, given a starting point, how far is it to any other point.
The map consists of cities (i.e. nodes) which are connected by roads (i.e. edges) where
each road has some cost associated with it. The costs depend on such factors as length, traffic, road quality, speed limit, etc.
Assume all the costs are positive and non-zero.
Now, you remember long ago taking an Algorithms class where you learned about Dijkstra's shortest path algorithm. This is
exactly what you need to find the cheapest route. You team up with one other person to do the job.
Before you start coding, you and your partner need to do the following:
- Thoroughly understand the algorithm! Your algorithms textbook discusses Dijkstra's algorithm, as does your data
structures text (they are a bit different). Do a problem by hand so you are certain of how it works.
- Decide on the implementation and data structures. What is the complexity? Can you
do better? Do you want to do better? For example,
- Think about graph structure (adjacency list or matrix). Since your graph is weighted, it may make sense to store it as an adjacency matrix where the entry matrix[i][j]
contains the cost of the edge between nodes i and j. This may increase the computational complexity but also may simplify other things.
Besides, you haven't ever used the matrix representation, so here is a chance to try it out.
- Some implementations use a priority queue to store the costs. Do you remember how to implement a priority queue? What priority queue operations are
needed?
- Decide what the GUI will look like. To display the results, draw the graph (e.g. using paint). Include the node index, the edge weight, and the shortest distance for each node.
For a given an
end node, you should be able to
identify the path associated with the shortest distance.
- What class structure will you use?
- To test the algorithm, you need to randomly generate graphs (nodes, edges, and weights) on which to run the algorithm.
Use some simple topology that will be easy to
draw.
- Break the project into subproblems to be accomplished one at a time, e.g. gui, generate and display random graph,
implement the algorithm e.g. first by brute force and then using a priority queue to improve complexity.
Once you have reviewed the algorithm and decided on the above items, you can start to program. You and your partner will use
pair programming.
Deliverables:
You will be asked to demo parts of the lab before the final due date:
- Tues, Feb 19: You should have completed the GUI and can generate a random graph.
- Thurs, Feb 21: You should have the brute force Dijkstra algorithm complete.
- Tues, Feb 26: The full program is due (with heap as a priority queue).
Be prepared to demo the full program in class or lab. Zip together project and have one partner email code to gorr (cc the other partner).
Please be sure to put CS343 Dijkstra in the subject line.
[top] [Schedule]
[Home]