Computer Science 351: Questions and Answers

Frequently asked questions about lab assignments, homeworks, lectures, or any other topic of CS 351 will be posted here.

If you have a question you'd like answered send email to In your email, please give the following information:

  1. Name of simplest test case that your program fails.
  2. Exact test that fails or errors out. (You can fail a test by giving the wrong answer which assertXXX(...) checks. Or you can fail by crashing with an assertion error or some other exception.)
  3. Exactly what the failure is: which Exception was thrown, or what JUnit says is wrong.
  4. What you think the data structure looks like at the point your code is called. (Tell us whether you have checked your guess in the debugger.)
  5. The snippet of your code (whole method typically) that went wrong. Mark the line where the exception was thrown from, if any.
  6. Explain then either
    1. Why you think your code should do what the test wanted, and why you think it shouldn't crash with that exception, OR
    2. Why you think the test case is doing the wrong thing.
    You are probably wrong in this part, but that's fine. If you weren't wrong, you wouldn't need help!

NB: See Java 8 API.

NB: See how to access your grades.

Homework #10

NB: The prev parameter of getPrev is badly documented. It should be the node previous to the entire subtree rooted at cur (which is not allowed to be null). Otherwise, as a student pointed out, it would always be the answer that the helper method is supposed to return! (The same is true for the prev of to_put.)

Q: What does checkThreading need to start off?

A: As with all our recursive helper methods on binary search trees, it uses a bureaucratic procedure. Each division needs to check the "next" links in their tree. But each (non-empty) division will have at least one next link to outside the division and so the supervisor needs to provide that outside link. So each node is told to check its subtree and is given the "next" node after all the nodes in the division. Some people are reading this as meaning the next node of the root of the division. But that would involve micro-managing the subdivision (telling the manager who their next should be). Normally, the division's root's next is within its right subdivision. So don't do that!

Q: What does "x is comparable" mean?

A: It means "x" implements Comparable<T> where T is the type of "x".

Homework #9

NB: Our efficiency tests didn't include testing the special Lexicon methods such as getNext and consumeAll. Please replace the file with this one.

NB: We've also heard of people adding fields (e.g. a calledNext field). Don't do that. Since we gave you the invariant and that didn't include the field, and even implemented the invariant chwecker, you can't add new fields. In some assignment (or in a later course), we might give you freedom to create your own data structure, but if/when we do so, you will need to come up with the data structure invariant too!

NB: We've noticed several people using _current incorrectly. This value should be used to determine what to remove, not what is next. So, suppose we are in the middle of iteration: the next element returned should not be affected by whether we call remove() first. The _pending stack should be the same regardless.

NB: Oops: we forgot to include the following test in your default package:

import edu.uwm.cs351.Lexicon;

public class TestInternals extends Lexicon.TestIteratorStack {

	public void test() {
		assertTrue(true); // just to make this look like a JUnit test,

Homework #8

NB: We missed an important efficiency test:

    public void testConsumeAllWithPrefix2() {
    	ArrayList<String> list = new ArrayList<>();
    	for (int i=1; i < MAX; i++) {
    		String pre = (BASE_LENGTH + i) + "";
    		lex.consumeAllWithPrefix(str -> list.add(str), pre);

Homework #7

Q: How do I run RandomTest?

A: The easiest way to run RandomTest (for homeworks that include it) would be to right-click the included lib/homeworkX.jar file in Eclipse's package explorer, and select "Run as" -> "Java Application". If RandomTest is included in the homework, you should see it under "Matching Items". Run it. If it continues running through tens of thousands of tests, your ADT is likely behaving correctly. If it stops and outputs a particular test case, this means your code has failed one of its randomly-generated tests, and you can debug based on its output. Feel free to copy the output into a JUnit test so you can use the debugger to step through it.

NB: The following email was sent to all students on October 19:

We discovered an inconsistency with the specification of enqueue, and the data structure invariant. enqueue was required to accept anything (including null) because the Javadoc didn't say anything about excluding null. However, the data structure invariant didn't permit nulls in the queue. It is possible to satisfy both requirements, but not easily. It would be cleaner to change the invariant to accept nulls, but our tests currently check for it. So, instead we're changing the specification of enqueue:
        @pre x != null
That means that if null is sent in to enqueue, an exception must be thrown (probably IllegalArgumentException).

We updated homework7.jar on our Software Depot about 5pm [October 19], (see Software Depot) so if you downloaded it before, you'll need to download it again. Otherwise, the old RandomTest requirea that your Queue accept nulls. The new RandomTest requires that it not accept nulls.

Q: In the internal tests, test12 is hard for me to unlock: The length of the array is 4. Then we call ensureCapacity with 300. 300 is way over the length of the array. So doesn't the capacity get doubled to 600 (or 601) ?

A: Doubling the capacity would take it to length 8 (or 9), which isn't big enough. When allocating a new array, you make sure it is at least twice the current array size. Not twice the size asked for.

Q: What are we supposed to pass to invokeUI ? A computation with a missing/void/Void type?

A: The Utilities class is provided to you, so you can look at the source code of invokeUI.

Q: I'm having a problem unlocking the test:

assertEquals("Baa", animals.front().poke());
assertEquals("Baa", animals.front().poke());
assertEquals(???, animals.dequeue().poke());
I enter Baa but get an error. Shouldn't dequeue return the thing that front returned?

A: Yes, it does, but then the test calls poke. What does poke do? When called the third time?

Homework #6

Q: In the invariant test test00 it requires that that the invariant fail immediately. But I've already assigned dummy etc to be legal.

A: Oh, I forgot that you might have assigned the dummy in its field declaration. Please add the following lines at the end of setUp in the nested class at the end of the

n5a = makeNode("five");
_doReport = false;
self._dummy = null;
self._cursor = null;

Q: How can we make the dummy's data field be a reference to itself? It's the wrong type!

A: You're right. The type is wrong. But you can use a cast to type E, and since Java doesn't know what "E" is, it will accept it. But if that invalid value ever escapes and gets to the client, the lie will be exposed and a ClassCastException will be thrown. The reason why we are having you do this step is metaphorically to place a landmine in the data that will make sure you never release the dummy's data to the client. (If getCurrent is implemented incorrectly, for example, it will cause the problem)

NB: There are some last minute clsrifications we neglected to get into your repos:

When creating your private static generic Node clss, please use a different name for the generic parameter. This will help you see the difference between uses and definitions of type parameters.
In insertAll, if there is no current element, the new elements should be inserted at the end of the Sequence. (This is the same as in previous homeworks but should have been more clearly stated.)

Homework #5

NB: To see where an infinite loop is: turn off all breakpoints and then Debug the Junit test. After a while, it will be obviously stuck. Click the Pause button (⏸). Go over to the "Debug" Pane and find a thread named "►Main" that should be "suspended", open it to find out what line the infinite loop contains.

NB: I just realized that we told you to do things in the order given, but check 4 cannot happen until 5a is done, or at least at the 'same time. It can't be done before. Sorry!

Q: In Group#clone(), how can we sever all ties to the original students if we're making a clone?

A: Perhaps you didn't read the Javadoc for clone? (The NB part is a joke, but the part before is important.)

Q: Can we implement the invariant checks in an alternate order?

A: Certainly! Our code mixes up the implementation very much.

Q: I get an error about project locked-tests not being available.

A: We corrected this error about 11:30am Tuesday. If you cloned before then you must Team>Pull to get the new repo. It's safe to do this no matter what. If you don't do it when you should then you will be unable to turn in your homework!

Homework #4

Q: In test2 (and also in test6), the test code creates a situation using code like:

hs._precursor = new Node(h2,hs._head);
This is supposedly bad, but the invariant says that the precursor must be null or point to a node in the list. This code has precursor point to the head. Surely the head is in the list! Why is this situation bad?

A: Thanks for working with an example and explaining why you think the test is wrong. This allows us to tell you: after the code you highlighted the precursor does not point to the head. It points to a new node, whose next field points to the head node. Two thing: (1) nodes don't point to things: variables (and fields) do; (2) if A points to B and B has a field that points to C, that is not the same as A pointing to C.

Q: I don't see getCursor declared anywhere!

A: That's because it's optional. You don't need to define it. We recommend that you do so in order to compute the value of the "ghost" field. If you have getCursor then methods such as advance() are almost trivial to write.

Homework #3

Q: The file you give us has a comment that states:

You will also be required to override the abstract methods count() and iterator().
What's count()? Is that supposed to be size() ?

A: Yes. Oops.

Homework #2

NB: The TODO comments in refer to "Sequence" when they should refer to "Song". The two helper comments should say

// TODO: Add note to the END of the song.  (or the song plays backward!)
// TODO: For each note in the song
// TODO:   call putNote on the track with the current time stamp
// TODO:   and then increment the timestamp by the ticks (see toTicks)
//         of the note's duration

NB: Hearing some of your questions, we want to emphasize that

"there is no current element"
is different than
"the current element is null"
In the first case, hasCurrent() returns false, and in the second case, it returns true.

Q: WHat do the two "TODO"'s at the top of refer to:

// TDDO: Add some meaningful locked tests
// TODO: Rename tests in numerical order

A: Oops. Some notes to ourselves were left in. Please ignore them.

Q: What is the name of a "catenate"d Song ?

A: Read the javadoc for the method in to see what it says.

Q: I'm unlocking a later test of a catenated song, and wopnder what the duration of e1 and e2 are.

A: You can see this in setUp. Sorry for not making it obvious in the code before the locked test.

Homework #1

Q: I get an exception and a message about "Usage" when I try to run the musicbox program. How can I run it?

A: The "Usage" says what sort of form your program arguments should be. You need to give a song file (from the songs folder) and other information in the "Program Arguments" section of the "Run Configuration" tab.

Q: I don't know how to implement hash code. What should I do?

A: The hash code should combine integers derived from the fields that are compared for equals. An integer field is usable as is. A double can be converted into an integer for hash code purposes using a method in class Double. When you combine values, the tutorials frequently use "31" to spread the values apart from each other. You may want to use a larger spread. Here's one example tutorial on hash code .

Q: Can we add our own helper methods?

A: In principle yes, but if you do the homework "properly" you shouldn't need to add helper methods, unless we mention them. But if (for example), you don't know the "this(...)" syntax for calling one constructor from another, then a helper method can avoid the need to duplicate code (good to avoid).

Q: For test16 it tells me the expected result is "f#4 x 0.5", but it's failing saying the actual result is "f#4 x 0.5". Why would it fail like this?

A: Under the hood, assertEquals(object1, object2) is checking that object1.equals(object2) returns true. If the test is failing, then these two objects are not being considered equal. Should they be?

Q: Transpose method changes a pitch to a higher or lower octave but it didn't work when I put that as an answer in the test.

A: On the handout:

Note transpose(int)
Return a new note transposed higher (or lower, if the argument is negative) by the given interval (number of MIDI values).
The new note is transposed by the interval based on the MIDI value. If the MIDI value of f#5 is 66, what is the pitch name for MIDI value 67?

Lecture Example

Q: Do we have access to the examples shown in lectures? Where do we find them?

A: You can use eclipse to import the lecture examples using repository path

Replace n at the end with the corresponding week number.

Homework Solution

Q: The handout says to check the solution to previous homework for examples. Where do we find them?

A: You can use eclipse to import the solution using repository path

Replace n at the end with the corresponding homework number and note that there is no .git at the end. When you try to import the homework solutions using default settings, you may encounter an error that says files already exist. To fix this, there are two things you need to do:
  1. At start up, choose a different workspace
  2. On import dialog, on the step where you can choose the local destination of git repo, type in a different name at the end of the path e.g homework2_solution.
Alternatively, you can ssh into (see instructions), change directory to the above path.

Accessing AFS through andrew

Q: You said our grades are on AFS and so is the quiz solution. How do we access files in $CLASSHOME/...?

A: You should ssh into (see instructions). Then you can change directory to the place of interest, e.g. your grade directory or the solution file and look at a file using more.

NB: While on andrew, you can check the status of a homework git, what you have pushed or not:

git --git-dir=/afs/ log

Eclipse Problems

Q: I accidently deleted a file. How can I restore it?

A: There are two ways: one is easier but can only restore an entire directory, the other is more complicated but can restore a single file.

First way, in "Package Explorer", right click on the folder where the deleted file belongs to, and select "Replace With" -> "HEAD Revision". Then click "OK". This will replace ALL files in the directory with the ones in last commit. So if you changed any other file in that directory, make sure commit the change on that file before using this approach.

Second way, select "Git Repository Exploring" from "Window" -> "Open Perspective" in menu bar. Then, look "Git Staging" tab in a sub-window. If you didn't do a commit (you shouldn't!) after having accidently deleted the file, you should see your deleted file in "Stage Changes". Right click the file and choose "Replace with HEAD Revision", the file should be restored.

Q: When I try to "push" I get an error: rejected: non fast-forward.

A: That message means you need to "pull" first before "push".

NB: See instructions to merge if you have any problems with push..

NB: Some easy instructions (PDF) for installing EGit on Eclipse. (Thanks to Brandon Bluemner)

Q: It says I can't run my programs because of a major/minor version error.

A: The problem was that the project was compiled on a machine with a higher version of Java (e.g. 7) than the current setup can handle (often Java 6). Clean the project and try again. ("Project > Clean ..." and then just clean the current project -- the one that doesn't work. No need to clean everything).

NB: A similar problem can happen if you use a non-default JRE in the project. Then nothing works, and you have a nasty red exclamation point on the entire project. You will need to go to Project Properties and choose the Java Build Path and then select the Libraries tab. The JRE library selected is marked as bad, delete and then "Add Library > JRE System Library > Workspace default JRE". Then it will clean automatically and rebuild.

AFS and Kerberos Installation

NB: It is no longer necessary to install OpenAFS on your home computer for CompSci 351

NB: In the instructions that follow, if you are on the campus network, you can use AD.UWM.EDU as the Kerberos realm (cell is still instead of CS.UWM.EDU and then use your University password.

Installation on Windows (64 bit)

  1. Go to
  2. Select the section Kerberos for Windows (MIT or Heimdal)
  3. Select Heimdal Kerberos, which takes you to a webpage at "Secure Endpoints"
  4. Select the latest Heimdal Kerberos (1.5.1 or later) for 64 bit. Run/Install this. (Typical install is fine)
  5. Next, on the same "Secure Endpoints" page, find a link to Network Identity Manager v2 (available separately) and click there.
  6. That brings you to a new page, scroll down to the download section and get the 64 bit regular download (not the SDK download). Run/Install this. (Typical install is fine)
  7. Now assuming you downloaded Heimdahl (not MIT) KfW, on your windows machine, bring up the following file in NotePad running as Administrator:
    Add a line after the line [libdefaults]. This new line should say
        allow_weak_crypto = true
    Then "Save" the file. If it doesn't let you save, then you probably didn't run NotePad as an Administrator. Quit NotePad and try again, this time running NotePad as an Administrator. (Apparently it's possible to run a program as administrator by using Control-Shift-Enter from the Search box under Start. Another possibility is to right-click the notepad application and choose "run as administrator".)
  8. Finally verify that this is working by doing the following in a Command Prompt window:
    kinit yourid@CS.UWM.EDU
    Type your CS kerberos password. If on campus, you can use AD.UWM.EDU instead with your panther password. If this succeeds, then continue. Otherwise, tell us the error.
  9. Finally, you can install OpenAFS itself. Go back to the Windows download page for OpenAFS and download the latest 1.7.X distribution. When you run it:
    1. Choose "Typical Install"
    2. On the "Configure AFS Client" Page: Choose "" as the default Cell (NOT And DISABLE "Integrated Logon". Other things should be enabled.
  10. The computer will need to restart. Let it restart and then log in again.
  11. Make sure the network is running (open a browser window).
  12. Start "Network Identity Manager". You might have to look for it.
  13. It will say you don't have credentials. Click to obtain new credentials.
  14. The dialog window will list your Windows logon and ATHENA.MIT.EDU. Change it to your Panther ID (not your student ID!) and CS.UWM.EDU (or, if on campus, AD.UWM.EDU).
  15. If the network is running, it should ask for your password. This is your kerberos password. (or if using AD.UWM.EDU, your panther password).
  16. If it works, you end up with a green credential. A delay of 30 seconds is OK.
  17. If there is a long delay (a minute or more) or a brief error message and THEN the green credential thing comes up, AFS is not working. Perhaps you specified the wrong cell ( ?). You will need to check the AFS information about your credential. Look at the Advanced view and see if you see something obviously wrong.
  18. Now you can use Eclipse. On Windows, remember to use backslashes. and START with two of them: \\afs\\users\classes\cs351\...
If you have problems, please indicate how far you got through these steps. Also, give the output of the following three commands (run in a Command Prompt window):
  1. net view \\afs
  2. kinit yourpantherid@CS.UWM.EDU
  3. aklog -d -c

NB: If you install Openafs 1.6.X on a Windows machine, don't expect us to be able to help you if it doesn't work. OpenAFS 1.7.X is recommended for all Windows installations.

Installation on MacOSX

  1. Download the software from
  2. Install the DMG that you have downloaded. ("Click icon to install") "This package will run a program .." (Continue)
  3. On the Client Cell Configuration, select Optionally cs can be the alias, but you won't need an alias.
  4. Install on the main hard disk. It will ask for your local password to get permission to install.
  5. Then if using Lion or later (e.g., Mountain Lion), open a terminal and use vim (see VIM documentation) to edit /etc/krb5.conf. At the prompt ~ $, type the following
    sudo vi /etc/krb5.conf
    This will ask for the local password, and then bring up the file. Make sure that you have at least the lines:
    allow_weak_crypto = true
    default_realm = CS.UWM.EDU
  6. Now you have finished the installation.

    In order to use OpenAFS to access your class files, you will need to get kerberos credentials and use them to get AFS tokens.

    kinit yourpantherid@CS.UWM.EDU
    Kerberos credentials (and the associated AFS tokens) expire after a time (typically 10 hours, sometimes 25 hours -- it can be set in your krb5.conf file).

Installation on Linux

If asked the following questions, here are some recommended answers:
AFS cell?
size of AFS cache?
1000000 (that is, one gigabyte)
run AFS now?
encrypt AFS traffic?
dynamically generate contents of /afs?
You should ensure that /var/openafs/cache has at least as much space free as you promise in your cache response. Best is that the cache is its own partition. The file system should be ext2, ext3 or ext4. Once you have installed it, continue with the instructions for MacOSX.

Troubleshooting an AFS/kerberos installation

Some OpenAFS errors are easy to fix. Use aklog -d in a command prompt / terminal window to determine the problem.

Error 56 (Authentication server unavailable)
This means you are trying to use the AFS client service to get tickets. This doesn't work. You have to use Network Identity Manager (Windows) and/or aklog (any).
No credentials cache file found
You haven't got Kerberos tickets with Network Identity Manager yet. First get tickets and then if the Advanced view doesn't show AFS tokens, then run aklog again.
enryption type des-cbc-crc disabled
You need to edit krb5.conf to allow weak cryptography as described above.
KDC has no support for encryption type
You need to edit krb5.conf to allow weak cryptography as described above.
error -1765328234
You need to edit krb5.conf to allow weak cryptography as described above.
missing XXX.dll
This means you installed MIT kerberos for windows 32 bit but are on a 64 bit machine. You should have gotten the 64 bit version from Secure Endpoints. Look carefully for the 64 bit link on the OpenAFS installation page. Uninstall the old NIM and re-install the correct one.
clock skew
This means your system clock is more than 5 minutes off the AFS server. You should make sure you have the right time zone (US Central) and then reset your system clock to agree with an external source, e.g. your cell phone.
Couldn't get AFS tickets
If you get an error message about, this means you accepted the default cell as instead of changing it to I don't know how to change it after installation (you could uninstall and reinstall and this time make sure to set the default cell), but you can also run aklog with a cell option:
aklog -d -c
The Network Identity Manager also has a way to get tickets from cells other than the default cell. It's in a hidden dialog. Go to the Options>AFS page, and then select your panther ID (half way up the page) and then select the AFS tab, and then add as a cell to use in the bottom dialog.
ktc 7
If you had OpenAFS working, and it stops working, and this is the error, it can be fixed by rebooting. Otherwise, this is a hard error to fix. This error no longer happens with the OpenAFS 1.7.X IFS client.
RPC server is unavailable
If this error happens when you try to navigate to \\afs\ this means your computer is not letting you access the AFS server. You probably have an overactive firewall.
client not found in kerberos database
You are using the wrong realm. You should use CS.UWM.EDU or AD.UWM.EDU, not a lowercase name or MIT.EDU etc.

NB: On Linux or MacOSX, the command line is used to authenticate to AFS. On Miller, I wrote a script called klog. You can make yourself a similar script. The only two things you MUST have are

kinit PantherID@CS.UWM.EDU
aklog -c

Q: On my Windows Vista PC, I can get a kerberos ticket, but don't get permission to access CS 351 files.

A: You need an AFS token. The network identity manager defaults to, but you need to change that (File>AFS>Preferences) to Then add '' as a cell to automatically get tickets for. Once you have a kerberos ticket, it will get your AFS tokens for you.

Q: How do I get to the CS 351 from my windows PC?

A: Use the ANC path: \\afs\\users\classes\cs351\...

Q: On my MAC/Linux computer, when I try to kinit, it says

client not found in the kerberos database.
A: This means the default realm is not CS.UWM.EDU, and so you have to specify it on the command line, or make it the default realm.

Q: If I get past the error I just mentioned, I get a new error:

Cannot get any kdc for realm CS.UWM.EDU
A: This means that your computer is prevented from accessing the KDC. This can happen if you are off the network, or have a paranoid firewall, or are using UWM's "Public" WiFi system.

Q: What should krb5.conf have in it?

A: Actually you don't need to have much of anything, unless you are using Heimdahl in which case you must "allow weak crypto" but the following is a reasonable contents:

allow_weak_crypto = true
default_realm = CS.UWM.EDU

  kdc =
  kdc =
  master_kdc =
  admin_server =

Q: On my Mac, I got the kerberos tickets; now how do I get AFS access.

A: Use "aklog" from a terminal window, or use one of the Third Party tools mentioned on the OpenAFS download page for MacOSX.

CS 351 FAQ / John Tang Boyland