$29
1 Programming Assignment
Write a program that prints out all integers of the form π
3 + π
3
, where π and π are integers in the
range [0, π], in sorted order while using π(π) space. That is, you cannot use an array of size π
2
and then sort it.
Input: A nonnegative integer n.
Output: A sorted list of all integers of the form π
3 + π
3
, where π and π are integers in
the range [0, π].
For each value integer of this form you will need to keep track of three things, the integer itself,
π
3 + π
3
, and the two integers used to create it, π and π. So, let’s denote our elements with the
triples (π
3 + π
3
, π, π). We do not need duplicate values (π
3 + π
3 = π
3 + π
3
) so we can assume
that π ≥ π.
Hint: You can start with the π + 1 values, (0
3 + 0
3
, 0,0), (1
3 + 0
3
, 1,0), … , (π
3 + 0
3
, π, 0). At
any given time if the current smallest element is (π
3 + π
3
, π,π) and π < π, then you may print
π
3 + π
3
, remove it from your data structure and add new element (π
3 + (π + 1)
3
, π,π + 1).
Otherwise, you may just print it, remove it and then find the next smallest element.
Your task is to write a java program, stored in a file named SortedSumsOfCubics.java that
contains a function SortedSumsOfCubics, which takes a nonnegative integer n as its only
argument, and prints out all the integers of the form π
3 + π
3
, where π and π are integers in the
range [0, π], in sorted order. For example, if the input is π = 3, the output should be,
0 1 2 8 9 16 27 28 35 54
The main function in your code should help you test your implementation by getting an integer
from input and sending it to the function above.
2 Evaluation Criteria
The programming assignment will be marked out of 25, based on a combination of automated
testing (various values for n, some very large) and human inspection.
Score (/50) Description
0 - 5 Submission does not compile or does not
conform to the provided description.
5 - 15 The implemented algorithm uses π(π
2
) space or
is inaccurate. That is, the outputs are not in sorted
order or some are missed.
15 - 20 The implemented algorithm uses π(π) space and
π(π
3
) or worse running time or minor errors.
20 - 25 The implemented algorithm uses π(π) space and
π(π
2
log π) running time and is accurate.
To be properly tested, every submission must compile correctly as submitted. If your
submission does not compile for any reason (even trivial mistakes like typos), or was not
based on the template, it will receive at most 5 out of 25. The best way to make sure your
submission is correct is to download it from conneX after submitting and test it.