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 items in the queue, then you should choose each one with probability 1/N, up to the randomness of StdRandom.uniform(), independent of past decisions. You can generate a pseudo-random integer between 0 and N-1 using StdRandom.uniform(n) from the StdRandom.java library.

Given an array, how can I rearrange the elements in random order? Use StdRandom.shuffle(). For reference, the shuffling algorithm is described on p. 93 of Introduction to Programming in Java.

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 is a subset? A subset is a set whose elements are elements of a larger set. Each element in the larger set is included at most once.

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 add extra public methods to the Deque or RandomizedQueue APIs? Can I use different names for the methods? No, you must implement the API exactly as specified.

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 generic array creation. 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.

Do I need to make my inner class variables private since checkstyle gives a warning? No, this is because the access modifier of the inner class instance variables is irrelevant - regardless of the access modifier, they can be accessed anywhere in the file. Note that outer class variables should always be private.

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.   Be sure to click the "Check All Submitted Files" button to verify that you submitted all of the required files and that they compile cleanly (modulo the expected warning when creating an array of generics).

Style and bug checkers. Our script uses Checkstyle (and the configuration file checkstyle-cos226.xml) and FindBugs (and the exclusion filter findbugs-cos226.xml) to analyze your code. Eclipse 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 (and, in some cases, it does not even indicate an error). If you don't understand a warning message, ask a staff member to explain.

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. The code is available from Review Section 1.3 of Algorithms, 4th edition booksite.


Kevin Wayne