Lab 1. I/O and Recursion
CS203, Spring 2006



1. (10pt) Write a Java program Tribonacci.java that reads an integer n from console input and outputs the nth Tribonacci number t(n). The nth Tribonacci number is defined by the following equations:

t(0) = 1
t(1) = 1
t(2) = 1
t(n) = t(n-1) + t(n-2) + t(n-3) for n >2

2.(10pt) Complete BubbleSort.java so that
3.(25pt) Complete the sort(int index) method which recursively sorts the array data into ascending order using the bubble sort algorithm.

4.(10pt) Write a program SortTest.java that records the time taken (in milliseconds) to sort arrays of 500, 600, 700, ..., 2000 integers, and writes the results into a text file results.txt in the following format:

# of elements  time taken
500 ###
600 ###
... ...
2000 ###

5. (5pt) Turn in Tribonacci.java, BubbleSort.java, SortTest.java, and results.txt through CSNS. Note that file uploading will be disabled automatically after 4:10pm, so please turn in your work on time.