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

Solved Midterm 1 on Data Structures and Object-Oriented Development II | CS 2606, Exams of Data Structures and Algorithms

Midterm Material Type: Exam; Professor: McQuain; Class: Data Structs & OO Development; Subject: Computer Science; University: Virginia Polytechnic Institute And State University; Term: Summer I 2008;

Typology: Exams

Pre 2010

Uploaded on 09/24/2008

ramblurr
ramblurr 🇺🇸

19 documents

1 / 8

Toggle sidebar

Related documents


Partial preview of the text

Download Solved Midterm 1 on Data Structures and Object-Oriented Development II | CS 2606 and more Exams Data Structures and Algorithms in PDF only on Docsity! CS 2606 Data Structures and OO Devel II Midterm 1 READ THIS NOW! • Print your name in the space provided below. • There are 9 short-answer questions, priced as marked. The maximum score is 100. • When you have finished, sign the pledge at the bottom of this page and turn in the test and your fact sheet. • 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. Name (Last, First) 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 computing the product of two N x N matrices: for (row = 1; row <= N; row++) { // 1 before, 2 each // pass, 1 to exit for (col = 1; col <= N; col++) { // 1 before, 2 each // pass, 1 to exit dotprod = 0; // 1 for (pos = 1; pos <= N; pos++) { // 1 before, 2 each // pass, 1 to exit dotprod = dotprod + a[row][pos]*b[pos][col]; // 7 } product[row][col] = dotprod; // 3 } } a) [10 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. ( ) ( ) ( ) 1 1 1 1 1 1 1 1 2 1 2 3 ( ) 1 2 1 2 1 1 2 7 1 3 1 1 2 4 8 9 2 4 8 9 2 4 8 9 2 4 8 9 N N N R C P N N N R C P N N R C N R T N N N N N N N = = = = = = = = = ⎛ ⎞⎛ ⎞ = + + + + + + + + + + +⎜ ⎟⎜ ⎟ ⎝ ⎠⎝ ⎠ ⎛ ⎞⎛ ⎞ = + + +⎜ ⎟⎜ ⎟ ⎝ ⎠⎝ ⎠ ⎛ ⎞ = + + +⎜ ⎟ ⎝ ⎠ = + + + = + + + ∑ ∑ ∑ ∑ ∑ ∑ ∑ ∑ ∑ b) [5 points] To what big-Θ complexity class does your answer to the previous part belong? (No proof is necessary.) Clearly, T(N) is Θ(N^3). CS 2606 Data Structures and OO Devel II Midterm 5 4. [12 points] In a B-tree of order 5, assume that the deletion of a particular value from a leaf node causes that leaf node to underflow, and that the underflow cannot be alleviated by "borrowing" (and therefore must be alleviated by "merging"). Is it necessary, or possible, or impossible that this "merging" will cause the parent of the leaf to underflow? If it is necessary, explain why. If it is possible, but not necessary, explain under what conditions the parent would underflow and under what conditions it would not. If it is impossible, explain why. Using examples to illustrate your argument, explain clearly. Merging requires that we move the data values from one child node into the other child node, AND that we move a value down from the parent node (unless we're in the root). So, merging reduces the number of data values stored in the parent node. Whether the parent node will underflow depends on how many data values the parent stored before the merge was carried out. For each node in the B-tree, there is a minimum number of values it must store. The value is 1 for the root node, and floor(m/2) for the other nodes. So, the parent will underflow iff it was at its minimum fullness before the merging took place. Therefore, it is possible but not necessary that the parent will underflow. Supporting examples were presented in class. CS 2606 Data Structures and OO Devel II Midterm 6 5. Suppose you are designing a buffer pool for an application that repeatedly accesses a collection of 10000 records, labeled R0, R1, …, R9999. a) [8 points] Logically, what is a replacement policy and why is one necessary? A replacement policy is the set of rules used to determine which element, if any, of the buffer pool will be replaced when another element is added to the pool. A replacement policy is necessary because buffer pools must have a finite cap on their capacity and therefore may become full. b) [4 points] Give a specific example of a possible access pattern for which LRU replacement will produce better performance than FIFO replacement, assuming that the buffer pool has 4 slots. Here's one simple example. Access four distinct records to fill the pool, say: R0, R1, R2, R3 Now, access the first record again (so it's not the LRU entry), then access a new record to force a replacement. LRU will replace R1 and FIFO will replace R0: R0, R1, R2, R3, R0, R4 Now access R0 again; LRU will score a hit but FIFO will score a miss: R0, R1, R2, R3, R0, R4, R0 CS 2606 Data Structures and OO Devel II Midterm 7 6. [6 points] The PR-quadtree partitions a finite, square region into four identical sub-regions (quadrants). An alternative type of quadtrees, let's call it an R-quadtree, allows unequal partitioning of sub-regions, as shown below. Given the same set of data points, would you expect the PR-quadtree to have more or fewer levels than an R-quadtree? Why? When a new element is added, the R-quadtree would never need to perform more than one split in order to separate it from any previous element. The PR-quadtree might have to perform many splits in order to achieve the necessary separation. So, the PR-quadtree might add more than 1 level on an insertion for which the R-quadtree would add a single level. However, note that it is possible that an insertion into the PR-quadtree will require NO splits but the same insertion into an R-quadtree might require 1 split. So, overall we'd expect the PR-quadtree to contain more levels (perhaps many more) than the R-quadtree given the same data. 7. [6 points] If a PR-quadtree stores points that fall into a world with side S, and the closest pair of points are a distance D apart, then the maximum height the PR-quadtree could have is given by 2log S D ⎡ ⎤⎛ ⎞ ⎢ ⎥⎜ ⎟⎜ ⎟⎢ ⎥⎝ ⎠⎢ ⎥ Explain why the bound involves the expression 2 . Do not attempt to prove that the bound is correct. We would guarantee that the closest pair of points is separated if the lowest level in the PR-quadtree contains leaf nodes whose regions are too small to contain both those points. Given a square of side X, the maximum distance between any two points in the square will be the length of the diagonal, which is 2X .
Docsity logo



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