|
Comp201: Principles of Object-Oriented Programming I
|
The following assignments will add the indicated number of percentage points to a student's total grade.
Submit this part of the extra-credit work as instructed in HW 12.
For this part of the extra-credit assignment, create a subdirectory called extra2 and save all work in this subdirectory. After you are done, clean the build directory of your project files to remove all class files. Zip the whole extra2 subdirectory and submit it to your Comp 201 WEBCT Extra assignment page.
Suggestion: Add the following method to LRStruct to make checking equality of lists easier:
public boolean equals(Object other) { return (Boolean) this.execute(lrs.visitor.LRSEqual.Singleton, other); }Where LRSEqual is the visitor from the 2006 Exam 2 (Prob. 2.ii).
Now, in your JUnit tests, simply define a "result" list that is an LRStruct that has the elements that you expect to see in the resultant list after running an algorithm on the test list. Your codes should look something akin the the following
assertEquals("Descr. of this test", resultList, testList.execute(algo, params));
() -- empty list case, splitting would result in () and ().
(a, ...) -- non-empty list case, recursion is at a. Need to recurse at least once to see if there are any more elements in the list. Initialize accumulator to a.
(a, b,...) -- recursion is at b, but accumulator is at a. If b was the empty list at the end, splitting now would mutate the host to (a) and return ().
(a, b, c,...) -- recursion is at c, accumulator is still at a. If c was the empty list at the end, splitting now mutate the host to (a) and return (b).
(a, b, c, d,...) -- recursion is at d, accumulator is at b. If d was the empty list at the end, splitting now would mutate the host to (a, b) and return (c).
(a, b, c, d, e, ...) -- recursion is at e, accumulator is still at b. If e was the empty list at the end, splitting now would mutate the host to (a, b) and return (c, d).
(a, b, c, d, e, f, ...) -- recursion is at f, accumulator is at c. If f was the empty list at the end, splitting now would mutate the host to (a, b, c) and return (d, e).
(a, b, c, d, e, f, g, ...) -- recursion is at g, accumulator is still at c. If g was the empty list at the end, splitting now would mutate the host to (a, b, c) and return (d, e, f).
(a, b, c, d, e, f, g, h, ...) -- recursion is at h, accumulator is at d. If h was the empty list at the end, splitting now would mutate the host to (a, b, c, d) and return (e, f, g).
In the above, how many different helper algorithms are needed to advance the accumulator only every other time the recursion advances?
Is the accumulator the particular value or is it the list that starts with that value?
What is the relationship between the list that starts with the accumulator and returned list?
(5
pts) Definition:
An empty binary tree is balanced. A non-empty binary tree is said to
be balanced if both of its subtrees are balanced and their
height difference is at most one. Given an ordered
LRStruct of
Comparable objects, construct a balanced BST
BiTree containing the same objects.
Recursively apply SplitHalf
to build the tree without comparing any objects. (Thus, you cannot
use the BSTInserter visitor because it
compares objects.) For example, the list (1 2 3 4 5 6 7 8) should produce:
5
/ \
3 7
/ \ / \
2 4 6 8
/
1
100 pts total.
Last Revised Thursday, 03-Jun-2010 09:50:16 CDT
©2007 Stephen Wong and Dung Nguyen