CS 61B Mock Exam
July 30, 2008
A
Disclaimer: This is mock exam is designed to give you hints for your review.
It by no means resembles the actual midterm and you should not use these
questions as the only basis in your exam preparation.
You have 45 minutes to complete this mock exam.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentCS 61B Mock Exam
July 30, 2008
A
Problem 1 (Asymptotic Analysis)
Suppose . Assume
and
are positive for all values of x. For each of the following statements,
say whether it must be true or must be false or could be either:
Either
True
Either
False
Either
Problem 2 (Hashing)
Suppose we have defined a hash set for storing elements of class MyClass with b buckets and chains
implemented as linked lists. First, n different elements are stored in the table. Now we wish to store
one more, called newElem, which is not equal to any of the others. We'd like to do it with as few
comparisons (calls to MyClass.equals) between newElem and other elements as possible. Ordinarily
we'd ensure this by choosing a very good MyClass.hashCode method. But there's a catch: a dastardly
adversary is trying to make the number of comparisons as large as possible.
In terms of n and b, what is the fewest possible number of comparisons it will take to add newElem to
the table if:
a) The adversary gets to choose MyClass.hashCode(), but then we get to choose newElem (knowing his
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '01
 Canny
 Data Structures, newElem, CS 61B Mock, 61B Mock Exam

Click to edit the document details