for (int i=0; i < n; i++) { for (int j=0; j < n*n; j++) sum += data[i] * data[j]; for (int j=0; j < 4*n; j++) sum += data[i] + data[j]; }
Algorithm: removeDuplicates for i=1 to n if isDuplicate (i) remove (i) endif endfor return n Method: isDuplicate (i) for j=1 to n if A[j] = A[i] return true endif endfor return false Method: remove (i) // Removes and performs a left-shift. for j=n-1 to i A[j] = A[j+1] endfor n = n -1
% java -jar ../algtest.jar ex1.props(You can run something similar with a DOS-prompt). The jar file contains an algorithm test environment which will run your program and perform some tests.
Note:
import edu.gwu.algtest.*; import edu.gwu.util.*; import edu.gwu.debug.*; public class MyPartition implements PartitionAlgorithm { public int leftIncreasingPartition(int[] data, int left, int right) { // Your code here } public int rightIncreasingPartition(int[] data, int left, int right) { // Empty implementation return -1; } public static void main (String[] argv) { // Your own test code here } }
Submission: