FAQ for Programming Assignment # 1

Question:
In the assignment you said something about random permutation vs. some other Random()?? That part has to do with filling up the array. Do we just leave the code as you have it?

Answer:
What I do now selects random numbers, but does not guarantee that these numbers are unique. Thus, if a sort completes with repetitions, you have no idea if these were the result of an error or just that the data had duplicates. I recommended that you guarantee there are no duplicates. One way to do this is to just produce a random permutation of the numbers from 1 to N (or 0 to N-1).

Question:
When adding delays, do you mean adding delays in 3 different places to make it fail?? Or have 3 different instances of the program where you can put one delay and cause the program to fail?? Or, just put 1 delay in the code that will make it fail

Answer:
There are at least three places where delays can cause trouble. However, having all three delays active simultaneously gives you more variables than you can control. In other words, even if the sort fails, you wouldn’t know why. Worse yet, it could fail due to one delay, but fix itself as a consequence of another one. Thus, you should set up the program so you can choose to activate one or more (typically just one) of the delays, and run the program for each of the three (or more) distinct single cases.

Question:
I don't have a zip drive. How else could I turn in my assignment? Could I zip it using Winzip and put it on a floppy?

Answer:
By zip, I meant WinZip, not a zip drive. You can send the zipped file directly to Mat, the GTA. There is no9 need to give us it in a floppy, zip or any other hard medium.

Question:
I've gone through the code for the EOSort and am somewhat confused. I don't understand why I get an array of 25 when your "N" value is 8. Could you clarify?

Answer:
The reason it sorts 25, not 8 numbers, is that the html changes the value of N. This is the html part that matters.

<APPLET>
<PARAM NAME="N" VALUE=25>
</APPLET>

Question:
As far as creating random permutations on "N" numbers I want to fill an array with values from 1-N and then swap them randomly, but I'm having problems with boundaries when generating the random indices to swap. Thank you for any insight that you can provide.

Answer:
I would not approach this by doing a random swap. Here is the essential idea behind the algorithm I would use.

for (int i=0;i<N:i++) a[i] = 0;
Random r = new Random();
int k = 0;
while (k<N) do {
 int p = r.nextInt(N);
 if (a[p] == 0) a[p] = ++k;
}

Question:
i was just wondering on what you meant by making the program fail... do you mean fail as in stops before the numbers are in proper order or fail as in does not do the sort properly??? because i can get the program to take forever to do the sort and to not execute it in the proper manner (ie. switches the wrong way) however, it always seems to sort out in the end.. is that what you are looking for???

Answer:
There are three clear types of failures:

  1. Create an array that does not contain the same numbers with which we started. An example is to destroy one or more values with replicates of other values in the list.
  2. Fail to converge. An example of this is constantly swapping values, even those that are already in order.
  3. Converge with a permutation of the original values that does not represent a sorted list.

In our case, converge has the simple meaning that no more swaps will ever occur. It does not mean that the threads will recognize this and actually stop. At least two of these are possible in your assignment.

Question:
I am having some issues with JBuilder7. I am not too familiar with Jbuilder but it is my understanding that to run the EOSort.java file that I downloaded from the course web page I need to start a new project. I used default settings. Then I added the EOSort.java file to the project. I right click the EOSort.java file and I build it. Next I click the green arrow and "run" the project but it asks me to set the Runtime Configuration. I am not sure how to set this up or if I am even going about it the right way.

Answer:
To run the threads project, download the zip file. You need to double click its jpx file (threads.jpx) to start JBuilder in the threads project. That already adds EOSort to the project. Running an applet/application can be done by right clicking on the main file (html for applet/java for application) and choosing run, or changing the project properties to specify the main file (the one that you wish to run when you press the run button). JBuilder will encourage you to do this whenever you try to run without having set up a main file to run.