Chapter 6 Dynamic Programming - Programming Assignment
CS 343: Analysis of Algorithms,
Spring 2008
Do the following problems:
-
Longest Common Subsequence - LCS
This was discussed in class. Work on your own. If you want, the program may be console based (i.e. no gui).
-
Bellman-Ford Algorithm with Negative Cycles Allowed
- Begin with your Dijkstra shortest path program from Chapter 4. You may work with the same partner as
before or, if you want, you may work alone (I don't recommend this).
- Modify your graph so that it is a directed graph rather than undirected. Modify the gui so you can tell
which direction the edges point.
- Modify how you set the random weights so that they can be negative.
- Implement the Bellman-Ford algorithm for weighted directed graphs. The algorithm should either identify the shortest path from
a given node to a fixed source
- Note, the paths are from a specified node
to the target and not the other way around. This didn't make any difference in the Dijkstra algorithm since the graph us undirected.
If there are negative cycles, it should tell the user that there are negative cycles (no paths are found in this case).
- Testing: Before running the algorithm on your randomly generated graph,
first test your algorithm on the graph in figure 6.23 (p. 294). You should be able to duplicate the last column in 6.23(b). Also, print out the
"first" array (we called it "previous" in the Dijkstra algorithm) and check by hand whether it is correct. Once you get it working, change the
8 (weight from c to b) to -8 so that there is a negative cycle. Can your program correctly identify the existance of a negative cycle?
Deliverables:
- Thurs, April 3: Have the graph generation and gui working on the Bellman-Ford Algorithm
- Tues, April 8: Have the Bellman-Ford Algorithm completed.
- Tues, April 15: Have the LCS Algorithm completed.
Be prepared to demo the programs in class or lab. Zip together projects and email code to gorr. In the Bellman-Ford
program, make sure that one of the partners sends the program and cc's the other. If you have chosen to work alone, please indicate that
in your email.
Please be sure to put CS343 DP-LCS or CS343 DP-Bellman-Ford in the subject line.
[top] [Schedule]
[Home]