COP 3503 Fall 2010 Programming Assignment #1 Assigned: Wednesday, 8/25/10

advertisement
COP 3503 Fall 2010 Programming Assignment #1
Assigned: Wednesday, 8/25/10
Due: Wednesday, 9/8/10
Problem: MCSP
The Problem
Susan spent all her money on textbooks and has turned to gambling. Since she knows
you can help her, she decided to gamble shrewdly. The rules of the game are
straightforward: each player gets a sequence of integers. The players must determine the
maximum product value that can be computed with non empty sub-sequences of
consecutive numbers from the given sequence. The winner is the one which gets first the
right result. As an example, the maximum sub-sequence product of the array:
0
-2
10
0
0
-6
-3
is the subsequence:
-6
-3
and has a product of 18.
The Input
The input consists of several arrays of size N integers. The first line of the input is a
single positive integer k, signifying the number of test cases. Each test case will follow.
The first line of each test case will contain a single positive integer N (0 < N) indicating
the size of array. This is followed by 1 line that contain N real numbers separated by
white space. The numbers in the array will be in the range [-127, 127]. The input will be
from the file "product.in"
The Output
You will output a single line for each test case. The line will follow the following format:
Test case #i: The maximal product is X.
where i represents the test case being processed, and X represents the maximal product of
that test case. The output should be to the screen.
Sample Input File
3
2
3 -1
3
6 -2 -3
5
0 -2 -7 0 13
Sample Corresponding Output
Test case #1: The maximal product is 3.
Test case #2: The maximal product is 36.
Test case #3: The maximal product is 14.
Theoretical and Experimental Analysis
You will analyze your code to determine a theoretical run-time and verify this work by
doing an experimental analysis of your implementation as shown in class. Do this work
in a separate Word document. First include the theoretical analysis, highlighting the
relevant parts of your code. Then, provide a chart with appropriate experimental runtimes for various values of N, the value of one dimension of the input array. Use this
chart to draw a conclusion about the experimental run-time of your algorithm. After you
are done with this part of the assignment, edit the code so it runs according to the sample
input and output listed above.
Grading Details
Using n as defined above, there are algorithms that solve this problem with the following
running times: θ(n3), θ(n2), and θ(n). Your program will be graded based on its
correctness AND efficiency. A correctly running program with a run-time of θ(n3) will
earn a maximum of 70 points. A correctly running program with a run-time of θ(n2) will
earn a maximum of 85 points. A correctly running program with a run-time of θ(n) will
earn a maximum of 100 points. But, remember that correctness is most important. You
will lose points for all incorrect test cases.
What to turn in
Turn in your code in a single file called maxproduct.java over WebCourses.
Turn in both your theoretical and experimental analysis in a file called Analysis.doc over
WebCourses. (You may turn in a .txt file instead if you prefer.)
Download