CPSC 311, Sec 501
Spring 2004
Homework


General Instructions:
  1. The numbers refer to the textbook. Don't confuse exercises (at the end of each section) and problems (at the end of each chapter).

  2. Write clearly and legibly. Grading will be based on correctness, clarity, and whether your solution is of the appropriate length.

  3. Don't forget to acknowledge all sources of assistance. Unless otherwise instructed, you must write up your homework on your own. Turn in this cover sheet with your assignment.

  4. Homework is always due at the beginning of class.

Homework 8. Due 12:40 PM, Tuesday, May 4, 2004


Homework 7. Due 12:40 PM, Monday, April 26, 2004.

Complete the assignment in Homeworks 5 and 6, by implementing Dijkstra's SSSP algorithm, Bellman-Ford SSSP algorithm, and Floyd-Warshall APSP algorithm. Use a binary heap (implemented with an array) for Dijkstra's algorithm.


Homework 6. Due 12:40 PM, Monday, April 12, 2004. Postponed to Wednesday, April 14!

Continue with the assignment in Homework 5, by implementing Prim's algorithm and Kruskal's algorithm. Use a binary heap (implemented with an array) for Prim's algorithm. Use the disjoint sets data structure with union by rank (clarified 4/9) and path compression for Kruskal's algorithm.


Homework 5. Due 12:40 PM, Friday, April 2, 2004. Postponed to Monday, April 5!

We are shifting gears here a little - this assignment is a programming assignment.

Using either C, C++, or Java, you are to implement a "graph toolkit". Your program must read in from a text file a description of a graph (see below for specification of the file format), and then provide the user with a menu of choices for what to do with the graph. The choices will include:

You are to design the format for the output. If you want to output something graphical, that is fine, but command-line is also fine. Make sure the format is something easy for a human to understand.

Input file format: The first line is either "U" or "D", indicating if the graph is undirected or directed. The second line is either "U" or"W", indicating if the graph is unweighted or weighted. The third line is the number of nodes in the graph, n. Nodes are numbered 1, 2, ..., n. The remaining lines in the file describe the edges of the graph, with one line per edge. In an unweighted graph, an edge from node i to node j would be represented by a line containing i and j, separated by a space. In a weighted graph, the two node ids would be followed by the weight of that edge (separated by a space). For example, a possible input would be:

U
W
3
1 2 5.3
2 3 7.6
3 1 10.2
to represent an undirected weighted graph that is a triangle with edge weights 5.3, 7.6 and 10.2.

Your program will be tested on our input files, so be sure you use exactly this format!

Use the adjacency list representation for the graph. For the Floyd-Warshall option, convert the adjacency list into an adjacency matrix.

Be sure your program runs on the CS department's Unix machines when compiled with gcc or jdk (as appropriate)

Turn in your code using the "turnin" program in the CS department Unix machines. (Turnin instructions available here.)

In addition to the code turn-in, you must turn in a brief hard copy writeup (like a README file) of what you did. It must explain the correspondence between the implemented functions and the choices (BFS, DFS, Topological Sort, etc.), and how to interpret the program output. This should only be about one paragraph long.

The breadth-first search, depth-first search, and topological sort are due on Friday, April 2. The others will be due a little later, but go ahead and plan for them now in your code.

Collaboration: Although you can obviously find code implementing these algorithms all over the place, you are to write your code all by yourself, from scratch, referring only to the pseudocode in the textbook. You can, of course, ask the TA or professor for assistance. The purpose of the assignment is to give you practice in programming and to increase your understanding of the details of the algorithms. Copying files off the web will not achieve these goals.


Homework 4. Due 12:40 PM, Friday, March 26, 2004


Homework 3. Due 12:40 PM, Wednesday, March 3, 2004


Homework 2. Due 12:40 PM, Wednesday, Feb 18, 2004


Homework 1. Due 12:40 PM, Wednesday, Feb 4, 2004