Name: ________________________________
Honor Code Acknowledgment: ___________________
Random Quiz # 5
CPS 100, Spring 1997
Due: February 14 (Redhat day)
Problem 1: Lake Eerie (2 points)
Describe in a sentence or two the changes to list caused
by the function Mystery. You might consider
as an example the list (1,2,3,4)
void Mystery(Node * list)
{
if (list != NULL)
{
list->next = new Node(list->info,list->next);
Mystery(list->next);
}
}
Problem 2: Big Oaks (2 points)
Describe the value returned by the function Mystery below
for a tree T.
int Mystery(Tree * t)
{
if (t == NULL)
return 0;
else if (t->left == NULL && t->right == NULL)
return 1;
else
return Mystery(t->left) + Mystery(t->right);
}
Problem 3: Oh-Boy Redux (6 points)
Part A:
What is the complexity, using big-Oh, of the call
Frib(n) for the function Frib shown below.
Justify your answer briefly.
int Frib(int num)
// postcondition: returns a number
{
int j,k;
int val = 0;
for(j=0; j < num;j++)
{
for(k=0; k < j; k++)
{
val += k;
}
}
return val;
}
Part B:
In binary search, one comparison results in removing half of the
elements being examined from any subsequent search. If a new kind of
comparison operator permitted two-thirds of the elements to be removed
with one comparison, what would the complexity (using big-Oh) of a search
of n elements be? Justify your answer briefly.
Part C:
Consider a list of integers in which the integers are stored in
non-decreasing order and in which the integer k occurs exactly
k times; these lists are called N-lists where N is the largest integer
in the list. For example, a 4-list is (1,2,2,3,3,3,4,4,4,4) and a five
list is a 4-list with (5,5,5,5,5) appended to the end.
If for every integer k in an N-list, half of the occurrences of
k are removed (actually k/2 are removed, where integer
division truncatates so that
for the integer 3, 2 occurrences are removed; for the integer 11, 6
occurrences are removed) then how many numbers are left
(using big-0h notation)? Justify your answer briefly.
Owen L. Astrachan
Last modified: Wed Feb 12 12:16:16 EST