COS 226 Programming Assignment Checklist: Online Bottleneck Paths


What's a Checklist

Since this is the very first assignment, let me take a few moments to discuss some general issues, before discussing specifics about Assignment 1. Before you do anything else, please read the Assignments Page, including the collaboration policy, lateness policy, and submission system if you have not done so already. The checklists are meant to supplement the assignment, and clear up any confusing points. They will also provide brief hints on getting started.

The programming assignments will require a good deal of time. The final source code may not be that long, but creating and debugging the code is a serious time commitment. It would be a mistake to wait until after Monday precept to start your assignments. You may be able to ask far more meaningful questions in precept if you already have worked on the program enough to know what the real difficult issues are.

Frequently Asked Questions

How much space can I use? It should be proportional to the number of elements N. For Part 1, a a single parent-link array st[] should suffice. For Part 2, you will need an array of vertex marks, say mark[]. For Part 3, you'll need to add an array of weights, say wt[].

Do I need to submit code for all three parts? No, if you succeed in getting Part 3 to work, only submit code for this part. However, we recommend that you keep working copies of your solutions to Parts 1 and 2 around in case you don't get Part 3 to work. In this case, submit the highest numbered part that functions correctly.

What should my program do with self-loops, e.g., 3 3 50? It should discard the edge because there is already a better path from node 3 to itself: the empty path has infinite capacity.

Could you clarify the statement: "you cannot waste time following pointers all the way to the root if there is an LCA that is much closer to the two vertices"? Imagine that the path between p and q is small, say 10, but the path from p to the root is huge, say 1 million. Your code should only follow roughly 10 pointers (20 or 30 would be OK too). If p and q are not connected, then you do need to follow both pointers all of the way to their roots.

Could you clarify the statement: "you cannot waste time re-initializing all the vertex marks"? You are free to initialize all of the vertex marks once at the beginning of your program. However, you cannot march through the entire array and re-initialize all of the vertex marks after each iteration. The amount of work spent re-initializing the marks should be proportional to the number of marks set in that iteration.

Which paths should I count when computing the "average of all path lengths"? For simplicity, only count the paths that you would be printing out if N were small. For the example in the assignment, the average path length is 3.25 = (3 + 1 + 4 + 5) / 4.

When I insert an edge p-q (or equivalently q-p), I can do it by either reversing the path from p to its root or the path from q to its root. Which should I choose? The decision is arbitrary. A good strategy would be to reverse whichever path is shorter.


Input and Output

Input Format: We will test your programs by running "a.out 10 < input10.txt", where input10.txt is a text file consisting of integers separated by white space. It should not matter whether the integers are separated by a single space, multiple spaces, or even newlines. You may use the program generator.c to generate sample inputs.

Output Format: Follow the output format in the assignment using printf() with the "%4d" or "%8d" formatting option (or some other reasonable value). Do not use tabs since these will appear different (and ragged) on different systems. Note that we changed the output for Part 3 slightly (on 2/6) to make coding a bit easier.

Possible Progress Steps

These are purely suggestions for how you might make progress. You do not have to follow these steps.

  • Step through the bottleneck demo to make sure you understand the details of the algorithm.

  • Download the quick union program and the sample data files by copying the bottle directory from ftp.cs.princeton.edu/pub/cs226 to your system. Depending on your system, you should be able to download the whole directory, instead of each file individually. You can do this via a browser or anonymous ftp.

  • Do Parts 1, 2, and 3 in that order. Be sure to thoroughly test your program after each part. This means that you should test your program on a variety of inputs, especially degenerate ones that are likely to break your code. It would be a big mistake to assume that your code works after successfully testing it on only one input file.
  • readme.txt

    Besides any problem specific information which is listed in each week's assignment or checklist, you should use this file to give the reader a high-level explanation of your source code and point to anything unusual or notable about your program (such as extra credit or known bugs).

    Submission

  • Use the Web based submission system https://courseinfo.cs.princeton.edu to submit your code. You only need to submit your code for Part 3. In addition to bottle.c and readme.txt, submit any additional files that we will need to compile your program.

  • We will compile your submission with a command like "gcc *.c". After you have submitted all of the required files, be sure to hit the Compile button. Ideally, your program should compile cleanly, i.e., without warnings. You risk losing a substantial number of points if you do not do this.

  • cos226 Home Page
    wayne@cs.princeton.edu
    Last modified: February 2, 2002