Programming Assignment 1 Checklist: Percolation


Frequently Asked Questions (General)

What's a checklist? The assignment provides the programming assignment specification; the checklist provides clarifications, test data, and hints that might be helpful in completing the assignment.

Where can I find the course policies regarding submission, lateness, grading, and collaboration? Please read the Assignments Page.

I haven't programmed in Java in a while. What material do I need to remember? For a review of our Java programming model (including our input and output libraries), read Sections 1.1 and 1.2 of Algorithms, 4th Edition.

Which Java programming environment should I use? We recommend the lightweight IDE DrJava along with the command line. If you use our Mac OS X or Windows installer, then everything should be configured and ready to go. If you prefer use another IDE (such as Eclipse), that's perfectly fine—be sure that you can use command-line arguments, read from standard input, redirect standard input and output, and add stdlib.jar and algs4.jar to your Java classpath.

What are the input and output libraries? We have designed a set of easy-to-use Java libraries in stdlib.jar for input and output that you are required to use in this course. Here are the APIs.

Where can I find the Java code for the algorithms and data structures from lecture and the textbook? They are in algs4.jar. Here are the APIs.

Can I use various Java libraries in this assignment, such as java.util.LinkedList, java.util.ArrayList, java.util.TreeMap, and java.util.HashMap? No. You should not use any Java libraries until we have implemented equivalent versions in lecture. Once we have introduced them in lecture, you are free to use either the Java library version or our equivalent. You are welcome to use common functions in java.lang such as Math.sqrt() and Integer.parseInt().

How do I throw a java.lang.IndexOutOfBoundsException? Use a throw statement like the following:

if (i < 0 || i >= N) throw new IndexOutOfBoundsException("row index " + i + " must be between 0 and " + (N-1));
While you are required to throw exceptions using throw statements as specified, you should not catch exceptions with try-catch statements—this will interfere with our grading scripts.

What should I put in my readme.txt file? Here is a readme guide.

When I try to submit files I get a message telling me "No Login found in header of file." How do I fix this? At the top of each Java file, include a header in format described in the readme guide.

How should I format and comment my code? Here are some recommended style guidelines. Below are some that are particularly important (and for which you will lose points if you ignore).

What is unit testing? It is testing of each method within a class. Ideally, it should be comprehensive enough to catch any error in the class.

What's the easiest way to copy a subdirectory from the COS 226 ftp site to my computer?


Frequently Asked Questions (Percolation)

What are the goals of this assignment?

Can I add (or remove) methods to (or from) Percolation or PercolationStats? No. You must implement the APIs exactly as specified, with the identical set of public methods and signatures (or you will receive a substantial deduction). However, you are encouraged to add private methods that enhance the readability, maintainability, and modularity of your program. The one exception is main()—you are always permitted to add this method to test your code, but the autograder will call it only if we instruct you to include it and specify its behavior.

Why is it so important to implement the prescribed API? Writing to an API is an important skill to master because it is an essential component of modular programming, whether you are developing software by yourself or as part of a group. When you develop a module that properly implements an API, anyone using that module (including yourself, perhaps at some later time) does not need to revisit the details of the code for that module when using it. This approach greatly simplifies writing large programs, developing software as part of a group, or developing software for use by others.

Most important, when you properly implement an API, others can write software to use your module or to test it. We do this regularly when grading your programs. For example, your PercolationStats client should work with our Percolation data type and vice versa. If you add an extra public method to Percolation and call them from PercolationStats, then your client won't work with our Percolation data type. Conversely, our PercolationStats client may not work with your Percolation data type if you remove a public method.

How many lines of code should my program be? You should strive for clarity and efficiency. Our reference solution for Percolation.java is about 80 lines, plus a test client. Our PercolationStats.java client is about 60 lines. If you are re-implementing the union-find data structure (instead of reusing the implementations provided), you are on the wrong track.

What should stddev() return if T equals 1? The sample standard deviation is undefined. We recommend returning Double.NaN but we will not test this case.

After the system has percolated, PercolationVisualizer colors in light blue all sites connected to open sites on the bottom (in addition to those connected to open sites on the top). Is this "backwash" acceptable? No, this is likely a bug in your Percolation. It is only a minor deduction, so don't go crazy trying to get this detail.

   % java PercolationVisualizer input10.txt
Percolation backwash

How do I generate a site uniformly at random among all blocked sites for use in PercolationStats? Pick a site at random (by using StdRandom to generate two integers between 0 (inclusive) and N (exclusive) and use this site if it is blocked; if not, repeat.

I don't get reliable timing information in PercolationStats when N = 200. What should I do? Increase the size of N (say to 400, 800, and 1600), until the mean running time exceeds its standard deviation.


Style and Bug Checkers

Style checker. We recommend using Checkstyle 5.5 (and the configuration file checkstyle.xml) to check the style of your Java programs. Here is a list of available Checkstyle checks.

Bug checker. We recommend using FindBugs 2.0.3 (and the configuration file findbugs.xml) to identify common bug patterns in your code. Here is a summary of FindBugs Bug descriptions.

Mac OS X and Windows installer. If you used our Mac OS X or Windows installer, these programs are already installed as command-line utilities. You can check a single file or multiple files via the commands:

% checkstyle-algs4 HelloWorld.java
% checkstyle-algs4 *.java                      
% findbugs-algs4 HelloWorld.class
% findbugs-algs4 *.class
Note that Checkstyle inspects the source code; Findbugs inspects the compiled code.

Eclipse. For Eclipse users, there is a Checkstyle plugin for Eclipse and a Findbugs plugin for Eclipse.

Caveat. The appearance of a warning message does not necessarily lead to a deduction (and, in some cases, it does not even indicate an error).


Testing

Testing. We provide two clients that serve as large-scale visual traces. We highly recommend using them for testing and debugging your Percolation implementation.

Visualization client. PercolationVisualizer.java animates the results of opening sites in a percolation system specified by a file by performing the following steps:

The program should behave as in this movie and the following snapshots when used with input20.txt.

   % more input20.txt
   20
    6 10
   17 10
   11  4
    8  4
    4  8
    0  0
   ...

% java PercolationVisualizer input20.txt
      Percolation 50 sites
50 open sites
Percolation 100 sites
100 open sites
Percolation 150 sites
150 open sites
Percolation 204 sites
204 open sites
Percolation 250 sites
250 open sites

Sample data files. The directory percolation contains some sample files for use with the visualization client. Associated with most input .txt file is an output .png file that contains the desired graphical output at the end of the visualization.

InteractiveVisualization client. InteractivePercolationVisualizer.java is similar to the first test client except that the input comes from a mouse (instead of from a file). It takes a command-line integer N that specifies the grid size. As a bonus, it writes to standard output the sequence of sites opened in the same format used by PercolationVisualizer, so you can use it to prepare interesting files for testing. If you design an interesting data file, feel free to share it with us and your classmates by posting it in the discussion forums.


Possible Progress Steps

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