COS 226 Programming Assignment Checklist: Randomized Queues and Dequeues

Frequently Asked Questions

Should I use arrays or linked lists in my implementations? In general we don't tell you how to implement your data structures - you can use arrays, linked lists, or maybe even invent your own new structure. What you have to do is abide by the specified bounds on resources (time, space). So, before you begin to write the code, make sure that your data structure will achieve the required resource bounds.

How serious are you about not calling any library function other than Std* or Integer.parseInt()? You'll receive a substantial deduction.

If a client creates two randomized queue iterators, should they return the items in the same order? No, each should return them in random order, independent of the other.

What is meant by uniformly at random? If there are N elements in the queue, then you should choose each one with probability 1/N, up to the randomness of StdRandom.uniform(), independent of past decisions.

How should I generate a pseudo-random integer between 0 and n-1? Use StdRandom.uniform(n) from the StdRandom.java library.

Given an array of items, how can I rearrange them in random order? Use StdRandom.shuffle(). (The shuffling algorithm is described on p. 93 of Intro to Programming in Java.)

What should my program do if dequeue() is called when the queue is empty? Throw a RuntimeException with a queue underflow error message. See Queue.java for an example.

What should my iterator do if the deque is structurally modified at any time after the iterator is created (and before it is does iterating)? You don't need to worry about this on this assignment. An industrial-strength solution (used in the Java libraries) is to make the iterator fail-fast: throw an ConcurrentModificationException as soon as this happens.

What should Subset do if the command-line argument k is negative? If k is larger than the number of strings read in? If k is negative, it should either print nothing or throw an exception. If k is too big, it should either print all of the strings in random order or throw an exception. In general, if we don't specify a corner case, you are free to handle it in any "reasonable" manner provided you document what it is.

What's the wrapper type for char? Character.

Can I make up my own names for the names of the classes and methods? No. You will lose a substantial number of points.

Can I add extra methods to the Deque or RandomizedQueue APIs? Yes, provided they are generally applicable to a variety of applications, e.g., a method size() that returns the number of items currently in the data structure.

The compiler says that my program uses unchecked or unsafe operations and to recompile with -Xlint:unchecked for details. Usually this means you did a potentially unsafe cast. When implementing a stack with an array, this is unavoidable since Java does not allow arrays of generic types. However, you will lose a substantial number of points if your programs produce such warnings unnecessarily. In particular, both client programs should compile without warnings.

I'm using Windows and my program doesn't work when I type echo | java Palindrome. What could be wrong? On Windows, the echo command without an argument outputs ECHO is on, so this becomes the input to your program. We will test on a machine where echo passes the empty string to your program.

Testing and Submitting

Submission.   After you have submitted all of the required files (Deque.java, RandomizedQueue, Subset.java, Palindrome.java, and readme.txt) the "Run Script" button on the submission system will appear. Be sure to hit the button and check that you submitted the right files and they compile cleanly (modulo the expected warning when creating an array of generics).

Our script uses Checkstyle (and the configuration file (checkstyle-cos226.xml) and FindBugs (and the exclusion filter findbugs-cos226.xml) to analyze your code. Eclispe users: there are plugins for checkstyle and findbugs that you can use directly with your IDE. The appearance of warning messages does not necessarily lead to a deduction (or, in some cases, evenindicate an error).

Readme.   Use the following readme file template and answer all questions.

Possible Progress Steps

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

  1. Getting started. Download the directory queues to your system. It contains the file StdIn.java that you will use to read in input characters from standard input.

  2. Stacks and queues. Review the code we used in lecture for generic stacks and queues. Review Section 4.3 of Introduction to Programming in Java.


Kevin Wayne