



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A midterm exam for the cs 2606 data structures and object-oriented development ii course. The exam includes six short-answer questions covering topics such as algorithm complexity, function complexity relationships, and container implementation design. Students are not allowed to use notes or electronic devices during the exam.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




CS 2606 Data Structures and OO Devel II Test 1
printed
Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.
signed
for (i = 1; i <= N; i++) { // 1 before, 2 each pass, 1 to exit
for (j = i; j <= N; j++) { // 1 before, 2 each pass, 1 to exit
if ( i * j <= N ) { // 2 each pass less = less + 5; // 2 if done } else { less = less – 1; // 2 if done } } }
a) [14 points] Using the rules given in class for counting operations, find a simplified function T(N) that counts the exact number of operations the algorithm would perform.
From the line-by-line analysis above, the complexity function would be:
( )
( )
( )
1 1
1 1
1 1 1
1
1
2
2
N N
i j N N
i j i N N i
i j j N
i N
i
= =
= = −
= = =
=
=
∑ ∑
∑ ∑
∑ ∑ ∑
∑
∑
b) [6 points] To what big-Θ complexity class does your answer to the previous part belong? (No proof is necessary.)
T* const Find(const T& D); const T* const Find(const T& D) const;
Explain carefully why both are needed; it would be useful to provide hypothetical examples of client code to support your explanation.
The second form is necessary so that the client can call Find() in a context in which the container object has been declared as a const object. For example, the client may have created a container object in one function and then
passed it to another function by constant reference:
void Foo(const BST
... ... = Tree.Find(.. .); ... }
Since Tree is const, the function Foo() can only call member functions of Tree that are declared with the const qualifier, and the call shown above would not be allowed unless there were a const version of Find().
On the other hand, the call shown above would only be allowed if the pointer returned by Find() is assigned to a suitably const pointer:
const int* const p = Tree.Find(.. .);
And, in this case, the client cannot use p to make any modifications to the target of p (which may actually be a good thing in most situations). But clearly in some cases, the client will want to call Find() to locate a data object and
then modify that data object in situ. Therefore, we also need the first form of Find() to allows things like:
void DeleteEntry(unsigned int Offset, Location L) {
... LocIdxEntry *p = QTree.Find(.. .); p->DeleteOffset( Offset ); ... }
a) [8 points] Draw the resulting AVL tree if the value 90 is inserted.
b) [8 points] Draw the resulting AVL tree if the value 70 is inserted (into the original tree).
Note: you may NOT use the theorem that states that big-O is transitive.
(Note: there is no reason to suppose that the same constants will apply for both relationships.)