




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
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
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Name (Last, First) printed
Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.
signed
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
N N N
R C P N N N
R C P N N
R C N
R
= = =
= = =
= =
=
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).
No other characteristics of the original drive design are changed, aside from the obvious change in the storage capacity. Describe what effect these changes, if any, will have on each of the three measures, and why.
The three factors are seek time, rotational latency, and transfer time.
The seek time depends solely on how far the head has to move when servicing a request. Since the second change reduces the radius of the platters but does not change the track spacing, the maximum distance the head could move has been reduced and therefore the average seek time will be reduced.
The rotational latency depends solely on how long it takes for the correct sector to rotate to the position of the head, and that depends on the rotational speed. Since the first change increases the speed at which the platters rotate, the average rotational latency will be decreased.
The transfer time depends solely on the rotational speed and the number of sectors to be read. The change in rotational speed will reduce the transfer time; the number of sectors to be read is independent of the drive parameters.
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.
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.
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
a) [4 points] What is the relationship between the number of values stored in an internal node of the B-tree and the number of children that node has?
The number of children an internal node has is 1 more than the number of data values in the node.
b) [9 points] B-trees and their relatives are generally used to index very large databases, in which even the index cannot be entirely stored in memory at once. Why is it better to use a B-tree, whose nodes store many values and have many children, rather than an AVL tree?
First, because B-tree nodes store many data values and AVL nodes store only one, a B-tree would have far fewer levels and therefore would require retrieving far fewer separate disk reads to retrieve nodes.
Second, reading a sector (or a few sectors) at once is almost as fast as reading just a few bytes of data from disk, so reading one of the larger B-tree nodes will cost only a little more than reading one of the AVL nodes.
destructor , and a(n)
copy constructor , and a(n)
assignment operator overload.