CS 537-2: Spring 2000
Programming Assignment 1


Frequently Asked Questions (FAQ) Last modified: Fri Feb 4 04:25:41 CST 2000 


Q1:
 Will we be given a set of test files for the project? Or do we have to come up with our own test files?
A:
 
You need to come up with your own test files to convince yourself that your program is behaving correctly in all circumstances.

An important part of learning how to create robust programs is in learning how to create good test cases. We've made things a little easier for you by outlining a list of problems that you could encounter and that you should think about.

You will not be able to see ahead of time the test files that we will run on Wednesday.


Q2:
 Can I have each of the threads write their individual sorted runs out to a temporary file, which are then read back in the merge phase?
A:
 
No, the threads must write their sorted runs to a buffer in memory.

The project lets you work on not only creating threads but also the data communication between the threads, although it is still on a very simple stage. In the second project, you will face a more complex communication problem. If all of the keys fit in main memory, it is more efficient to keep them in memory rather than writing them out to the (very slow) disk.


Q3:
 For the merge phase, can I copy each of the sorted runs to a single buffer and then just sort that buffer?
A:
 
While this would still give you the correct results, its not how we want you to perform this step.

You need to actually merge the sorted runs. As stated in the specification, one approach is to have a single thread compare the first key in each run, pick the minimum key, copy it to the output list, and remove that key from the top of its run. If this step is repeated until all keys have been removed from every run, the output list will contain all of the keys in sorted order.


Q4:
 Do I have to turn in a README if I didn't make any new design decisions and I didn't find any bugs?
A:
 
Yes, always turn in a README; for this assignment, it should have two sections.
  1. Design decisions: For this assignment, you should at the very least describe the data structure you used to communicate the sorted runs between the multiple sorter threads and the single merger. You should also say how you sorted the keys into runs: did you write your own code or did you use an existing Java routine?
  2. Known bugs: If you can't find any bugs in your program, just state this. However, if you do have bugs that you know of, it will be to your advantage to report them; if you fail one of our tests that you previously described as a bug in your program, we may be able to give you a few points.

Q5:
 Do I have to create a new thread for merging?
A:
 You don't have to create a new thread to perform the merge. You can just have the main thread of control do this work.

Q6:
 What should I do if there is whitespace (e.g., a space character or a tab) on a line with a valid non-negative integer?
A:
 
To test the correctness of your sort, we will generally be using files without whitespace.

If a line does contains any white space, you can flag that as an error. As with all errors, you should print out the filename, the linenumber, and the contents of the line. (You might find that surrounding the contents of the line with quotes when you print it out is helpful for seeing if whitespace or a carriage return is being included in the string.)


Q7:    How to open a file to read or write in Java?
A:

Various Classes and Methods are defined in Java to deal with file input and output. Sometimes it is a little bit confusing. If you have
difficulties in this, please go to the course website and take a look at the tutorial written by Prof.  Solomon, Java for C++ Programmers. In the part "Input and Output", you may find some examples. It would be helpful.

But the example given for writting a file doesn't check whether the file has existed or not. You may go to the Java API webpage and look at the File class. It might be able to give you a hint about how to do the checking. If you have another way to do it, it is fine as long as it works.