Issues: Design: Interface Data Structures Classes Implementation: Interface Inheritence (Applet) Overload Construct ? (vary number items, loop count?) Data Structures Array (Lab 2) Vector/ ArrayList (Lab 2) Items as Objects (and the wrapper construct) (Lab 2) Threads Algorithms Recursion (Lab 2) ConcurrencyExpected goals:Programmer will acquire skills (and tools) to manipulate and use
Java and Objects pre-defined classes user-defined classes Performance Measurements Random Number Generators Timing mechanisms Recursion (Lab 2) manipulation of objects (with IVs as "pointers") concurrent processes & synchronizationWhat is it about?
There are many algorithms for finding the range of a set of numbers A = {a(i)}. One is simply to find the minimum and then the maximum of the set independently, and subtract (henceforth, "the obvious algorithm").
Another (abstract) methodology is to use the divide-and-conquer technique. The idea here is to break the problem (or data) into parts (divide), solve each part (conquer), and then bring the parts together for the overall solution.
One implementation for this could be to recursively find the minimum and maximum of both halves of A, and compare the minima to get the global minimum, compare the maximum to get the global maximum, and subtract (henceforth, the "recursive algorithm").
A second divide -and-conquer technique is to effectively simulate the recursive algorithm, which appears to operate "top-down", by working "bottom-up"; that is, compare pairs of elements of A, and keep track of the minimum of the pairwise minima, and the maximum of the pairwise maxima, and then subtract (henceforth, the "bottom-up algorithm").
Your job is to write programs for two of these algorithms (one "choice" must be recursion), and then to compare their running times by generating several sets of random data, and timing the two programs on random data sets.
Here are some hints:
Define pre- and post-conditions for the conceptual function "Range (A, n)". Then define the specifications for each implementation of the range function, say "ObviousRange", "RecursiveRange", and "BottomUpRange". The parameters that are passed should be identical for all of these, and each should return the range of the set as its value. Note that the input vector A should not be changed in any way.
For Lab 1, in order to get random data, you may simply fill an array of real variables with, uniformily distributed real numbers returned by the pre-defined Java class that generates random numbers. Seed values will be provided so that everyone ends up using the same "random" data!
On most systems, it will be possible to invoke a built-in function or routine that returns the elapsed CPU time since some reference time. Figure out what this is, and use it for timing your programs (Java might not have this yet, but don't worry, we will work it out).