COM1201 Spring 1997 Professor Fell QUIZ 3

Problem 1: ( 5 points) Given the function int BB(int n), fill in the table below.
a.
int BB(int n){
	if (n == 0) return 0;
	if (n == 1) return 1;
	if (n % 2) return 1 + BB(n / 2);
	return BB(n / 2);
}

n in Decimaln in BinaryBB(n)
2  
5  
8  
13  
31  

b. What does BB compute?

 

Problem 2: Consider the following code

void main(){
	int N = 100;
	int* A = new int[N];        		//a.
	for (int i = 0; i < N; i++)     	//b.
		A[i] = RandomLong(1, 1000); 
cout << Search(A, 100, 500); //c. } int Search(int A[], int size, int key){ //d. for (int i = 0; i < size; i++) if (A[i] == key) return i; return -1; }

Explain your answers.


Last Updated: April 19, 1997 2:52 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/Q3/quiz3.html