COS 226 Programming Assignment Checklist: Randomized Queues and Dequeues

Frequently Asked Questions

How serious are you about not calling any library function other than Std*? You can also call Integer.parseInt() in Subset.java, but you should not call any other library function.

How should I read from standard input? In this course you will use our home-brewed library StdIn.java to read text from standard input. For those of you that didn't take COS 126, read Section 1.5 of Introduction to Programming to learn how to use it. Note that there is a DrJava bug that prevents StdIn.isEmpty() from returning true, so you must use the Terminal (OS X) or Command Prompt (Windows) to execute your program.

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.

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 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.

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? 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? Larger than the number of string 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 should I print out if the input is a Watson-Crick palindrome? Something informative, such as yes, true, or is a W-C palindrome.

Can you give me some examples of Watson-Crick palindromes? Yes: "AAAACGTTTT, "ATATATAT", and "". No: "AAAA", "AAAAGTTTT", "ATAATA", "ZZZZ" and "AaTT".

What's the wrapper type for char? Character.

Can I make up my own names for the names of the classes and methods? No.

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.

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.

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 also plugins for checkstyle and findbugs that you can use directly with your IDE. The appearance of warning messages does not necessarily indicate an error or lead to a deduction.

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