Lab 1 Discussion: Analysis, Design, Implementation

Lab 1: Discussion: Analysis, Design, Implementation



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) Concurrency
Expected 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 & synchronization

What 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).

Actual timings of the functions may still be difficult, since the time to find the range of even a fairly large set will be so small as to be negligible compared to the resolution of the clock. The easiest way around this is as follows (assuming your compiler is not too smart): Write a loop that does nothing, and time it:

Let t(0) be the time it takes to execute the empty loop. Then, after generating the data in the array A for a particular value of n, time the loop (shown for "ObviousRange"): Let t(1) be the time for this loop. Now, the time taken by ObviousRange on this random problem of size n is simply

The value of SAMPLES should be set high enough that t(0) and t(1) are observed to be substantially larger than the clock resolution.

You should use 5 different random sets of each size, and average the runningtimes on the 5 sets, for each function. You should use set sizes n = 100, 200, 500, 1000. Thus, somewhere the program should have loops:

For data sets of size n, use the initial seed n to generate your random data.


Specifics

	CLASS: TIMER  
		(Given a method and input, time the code)
	CLASS: RANDOM NUMBER GENERATOR
	CLASS : PERFORMANCE_ANALYSIS
			2 RANGE METHODS

GUI
	CLASS: APPLET  (I will help with this one)
In Lab 1 we will work mainly with the timing mechanism and we will be considering two different simple algorithms (methods) to determine the range. In Lab 2 we will consider different data structures, which might, of course, also change the algorithms. Specifically, we will work with vectors and individual objects using concurrent threads

In Lab 2, we think of the linkage of objects as an "abstract" linked list - each object points to the next element in the list