Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 2606 Midterm Exam: Data Structures and Object-Oriented Development II - Prof. William D, Exams of Data Structures and Algorithms

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

Pre 2010

Uploaded on 11/09/2008

randyjarrett
randyjarrett 🇺🇸

1 document

1 / 7

Toggle sidebar

Related documents


Partial preview of the text

Download CS 2606 Midterm Exam: Data Structures and Object-Oriented Development II - Prof. William D and more Exams Data Structures and Algorithms in PDF only on Docsity! CS 2606 Data Structures and OO Devel II Test 1 1 READ THIS NOW! • Print your name in the space provided below. • There are 6 short-answer questions, priced as marked. The maximum score is 100. • Aside from the allowed one-page fact sheet, this is a closed-book, closed-notes examination. • No laptops, calculators, cell phones or other electronic devices may be used during this examination. • You may not discuss this examination with any student who has not taken it. • Failure to adhere to any of these restrictions is an Honor Code violation. • When you have finished, sign the pledge at the bottom of this page and turn in the test and your fact sheet. Name (Last, First) Solution printed Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signed CS 2606 Data Structures and OO Devel II Midterm 2 1. Consider the following algorithm: 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 ( ) 1 2 1 2 2 2 1 1 6 4 2 6 6 4 2 6 6( 1) 4 2 6 6 10 2 ( 1) 6 6 10 2 2 3 7 2 N N i j N N i j i N N i i j j N i N i T N N i N i N N N N N N = = = = − = = = = =   = + + + + + + +      = + +      = − + +    = − − + + = − + + + = − + + = + + ∑ ∑ ∑ ∑ ∑ ∑ ∑ ∑ ∑ b) [6 points] To what big-Θ complexity class does your answer to the previous part belong? (No proof is necessary.) Obviously, it is 2( )NΘ . CS 2606 Data Structures and OO Devel II Midterm 5 4. Consider the AVL tree at right: 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). 50 25 75 60 80 50 25 75 60 80 70 75 50 80 60 90 25 50 25 75 60 80 90 50 25 60 75 70 80 60 50 75 70 80 25 CS 2606 Data Structures and OO Devel II Midterm 6 5. The PR-quadtree partitions a finite, square region into four identical sub-regions (quadrants). An alternate type of quadtree, let's call it an R-quadtree, allows unequal partitioning of sub-regions based on the actual locations of data objects, as shown below. a) [8 points] Given the same set of data points, is it possible that insertion into the PR-quadtree would require splitting but insertion into the R-quadtree would not? If yes, give an example to illustrate how this could happen. (A clear diagram would be sufficient.) If not, explain why not. It should be obvious that either type of tree will store a single data point without any splitting, and that both will require at least one split when a second data point is inserted. However, after that, things may be different; suppose that A and B are inserted first: The PR-quadtree (on the right) required two splittings, while the R-quadtree (on the left) required only one. But that's not exactly what the question was asking (both DID require a split when B was inserted). However when C is inserted the PR-quadtree must split again, but the R-quadtree already separates the values. b) [8 points] Given the same set of data points, is it possible that insertion into the PR-quadtree would require splitting but insertion into the R-quadtree would not? If yes, give an example to illustrate how this could happen. (A clear diagram would be sufficient.) If not, explain why not. Take the same starting point as above, but place the third point C in a different spot: Now, the PR-quadtree does not require performing another split, but the R-quadtree does. A B A B C C A B A B C C CS 2606 Data Structures and OO Devel II Midterm 7 6. [16 points] Recall the definition: Let f and g be non-negative functions of n . Then f is ( )gΟ if and only if there exist constants 0N > and 0C > such that, for all n N> , ( ) ( )f n Cg n≤ . Prove the following fact: if f , g and h are non-negative functions of n, and f is ( )gΟ and g is ( )hΟ then f is ( )hΟ . Note: you may NOT use the theorem that states that big-O is transitive. proof: Suppose that f , g and h are non-negative functions of n, and f is ( )gΟ and g is ( )hΟ . Then from the definition, there exist constants 0N > and 0C > such that, for all n N> , ( ) ( )f n Cg n≤ . And, there also exist constants 0M > and 0D > such that, for all n M> , ( ) ( )f n Dg n≤ . (Note: there is no reason to suppose that the same constants will apply for both relationships.) Let max( , )R N M= and let E CD= . Then we have that, for all n R> : ( ) ( ) since ( ) since ( ) since f n Cg n n R n N CDh n n R n M Eh n E CD ≤ > ⇒ > ≤ > ⇒ > = = Therefore, by definition, we have that f is ( )hΟ . QED
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved