Homework 7

Due: Wednesday 3/30/2005 by 12:00 p.m.

Work on parts 1 and 4 with a lab partner. All the rest is meant to be individual work.

Part 1 is to be turned in on Th morning, in class. For Part 4, email Ileana by Sunday night your choice of topic (and tell me who is your lab partner). Part 4 is to be presented in class, on Th morning. Everything else, as usual.

**On paper**: trace the execution of the recursive Fibonacci function for n=5. Draw the stack at all steps, make sure you understand where variables are stored and where the current value of n is taken from.

**Merge Sort**: reusing code from a previous homework (in terms of main program or applet), replace Selection Sort with the Merge Sort program discussed in class today. More precisely, you must separately implement a function**merge**to merge two sorted lists (this is the "conquer" part of the algorithm) and use it in the MergeSort function.

Warning: there is a subtle issue that you may discover as you work on this function. Namely, when you merge, you need a separate array where you will place the merged data (different from the two input arrays). I want to hear on Tuesday what you think about possible implementations of this function, and then we will discuss the standard way of doing it.

**Ackermann function:**implement a small java application to test the Ackermann function on small values of its parameters. Use the on-line resource for the definition of the function, and test it on values that are in the linear, "exponential" and super-exponential category (x=3, x=4, x=5?). How far can you go with the exponential.

**Distance to the Moon:**find the distance from the Earth to the Moon (a web search will take you to at least one such resource), convert it to some small unit (say, milimeters). Then try to figure out what value y for second parameter of the Ackermann function A(4,y) will be as large as the distance to the moon.

- Choose a
**topic in Java**that we haven't yet covered. Research it with your lab partner. Write a tiny program to test it. Present it in class to your classmates. For extra credit, use it to improve some aspect of a previous (or current) homework.

Suggested examples include: try/catch/throw, from Java tutorial (click on Lessons and then Lesson 3, packages and exceptions). Strings. Any new GUI gadget. Vector or Queue classes in Java.

**Queue class**: Develop a Java class, a Java application and a Java applet to implement and test a queue data structure (for integers).

The Queue data structure has the basic queue operations In and Out, Full and Empty, plus a function Print for testing and Draw for visualizing. The queue implementation is circular, and the allocated size is EXACTLY 3 (to allow for easy testing). IN and OUT should print error messages when the queue is full (resp. empty).

The (application) testdriver should be menu-based, with one option for each of the five operations (IN, OUT, EMPTY, FULL and PRINT).

The applet should have buttons for all the above operations. In addition, it should correctly visualize the queue by representing (drawing) only the part of the allocated structure that is currently occupied.

An older homework 5.

Ileana Streinu