COM1201 Spring 1997 Professor Fell QUIZ 4

1. (5 points) Show a NEAT drawing of the resulting list when D(list) is executed and explain briefly what the function D does.



2. (5 points) Show the output when a call is made to H(4).

void H(int N){
	cout << N << endl;
	if (N > 1) {
		H(N-1);
		H(N-2);
	} 
}

3. (5 points) Given the function K() below, show the output caused by the following calls:

cout << "K(4) = " << K(4) << endl;
cout << endl;
cout << "K(3) = " << K(3) << endl;

int K(int N){
	static int count = 1;
	cout << setw(8) << count++ << setw(8) << N << endl;
	if (N == 0) return 1;
	if (N == 1) return 1;
	return K(N-1) + K(N/2);
}

4. (5 points) Write a recursive function:

int Q(int A[], int size)

that returns the maximum value among: A[0], A[1], . . . , A[size-1].


Last Updated: April 27, 1997 10:15 pm by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1101/QUIZ/Q4/quiz4.html