Question: Analyze algorithm efficiency with empirical tests Trace program execution with the debugger This exercise involves several algorithms for generating random permutations of the integers in

Analyze algorithm efficiency with empirical tests Trace program execution with the debugger
This exercise involves several algorithms for generating random permutations of the integers in 1..N. For example, when N =5,[3,1,5,4,2] and [1,5,2,4,3] are legal permutations, but [4,2,1,5,1] is not because the integer 1 is duplicated and 3 is missing.
The files Permutations.java and PermutationTester.java contain most of the code for the exercise. Create a new Java project in Eclipse and load these files into it.
TheRandom classhasmethodsforgeneratingpseudorandomnumbers.ThemethodnextInt(n)returnsa random integer in 0..n1.
Tracing in debug mode
Open the PermutationTester class in an editor window. Doubleclick in the
left margin next to the statement p.algorithm1(a);
This should display a blue dot next to the statement, which marks a "break
point". When run in debug mode, the program will pause at this line. Click
the bug icon to start execution of the program. The program will stop at the breakpoint. Eclipse will also change to the "Debug perspective"
that shows panel with a list of all visible variables and their
values in the upper right corner.
1) What values are stored in array perm?
Click the Step Over icon to execute the method call.
2) What values are stored in array perm now? It is not correct according to
the problem specifications described above. What is wrong?
The error is in the statement inside the dowhile loop in the algorithm1
method of the Permutations class. Fix the error (check the Javadoc for the
nextInt method if necessary) and run the tester in debug mode again to make
sure it is now correct.
Add two more statements to the main method to also run algorithm2 and
algorithm3. Run the program in debug mode again and execution will pause at
the breakpoint.
3) Advance one statement and write down the contents of array perm after
algorithm1 executes. Do the same for algorithm2 and algorithm3.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!