CS 2606 Data Structures and Object-Oriented Development II - Test 1 - Prof. William D. Mcq, Exams of Data Structures and Algorithms

The instructions and questions for test 1 of the cs 2606 data structures and object-oriented development ii course. The test covers topics such as big o notation, binary search trees, matrix operations, and buffer pools. Students are required to answer short-answer questions and are not allowed to use laptops, calculators, or other electronic devices during the examination.

Typology: Exams

Pre 2010

Uploaded on 09/24/2008

ramblurr
ramblurr 🇺🇸

19 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 2606 Data Structures and OO Devel II Test 1
1
READ THIS NOW!
Print your name in the space provided below.
Unless a question involves determining whether given C++ code is syntactically correct, assume that it is. Unless
a question specifically deals with compiler #include directives, you should assume the necessary header files
have been included.
There are 8 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
pf3
pf4
pf5

Partial preview of the text

Download CS 2606 Data Structures and Object-Oriented Development II - Test 1 - Prof. William D. Mcq and more Exams Data Structures and Algorithms in PDF only on Docsity!

READ THIS NOW!

  • Print your name in the space provided below.
  • Unless a question involves determining whether given C++ code is syntactically correct, assume that it is. Unless a question specifically deals with compiler #include directives, you should assume the necessary header files have been included.
  • There are 8 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

  1. Assume that f(n), g(n) and h(n) are positive-valued functions such that the following are true:

∀ n ≥ 7, f n ( ) ≥ 3 g n ( )

∀ 0 ≤ n ≤ 10000, h n ( ) ≤ f n ( ) ≤ g n ( )

a) [10 points] What does the first fact given above imply regarding any big-Ο, big-Ω and/or big-Θ relationships between the functions? Be complete. No justifications are needed.

By definition, f(n) is Ω(g(n)). If we divide through the inequality by 3, the resulting inequality implies that g(n) is O(f(n)).

b) [10 points] What does the second fact given above imply regarding any big-Ο, big-Ω and/or big-Θ relationships between the functions? Be complete. No justifications are needed.

Since the second fact only implies that certain bounds apply for a finite range of values of n, no conclusions about O, Ω, or Θ follow from it.

  1. [10 points] A BST implementation may use a hierarchy of node types to save memory. Write C++ declarations for the necessary node types, making good use of inheritance. Do not show member function implementations.

Here is a minimal implementation:

template class nodeWOPtrs { // leaf node type public: T Elem; virtual ~nodeWOPtrs() {} };

class nodeWithPtrs : public nodeWO Ptrs { // internal node type public: nodeWOPtrs Left; nodeWOPtrs Right;**

nodeWithPtrs(); // needs default constructor to // guarantee pointers are set };

  1. [8 points] In a B-tree of order 101, assume that the deletion of a particular value from a leaf node causes that leaf node to underflow, and that the underflow can be alleviated by "borrowing". Is it necessary, or possible, or impossible that this "borrowing" will cause the parent of the leaf to underflow? Explain clearly why or why not.

It is impossible that this situation will cause the parent of the leaf to underflow. If the leaf underflows, and "borrowing" is possible, then the relevant sibling must contain at 51 values (so it won't underflow after losing one). A value is moved from that sibling to the parent, where it replaces the value in the parent that falls "between" the two leaf nodes, and that value is moved into the leaf that underflowed.

This does not change the number of values stored in the parent, so there is no possibility the parent can underflow.

  1. [7 points] A B+ tree differs from a B-tree in two respects, one being that each leaf node has pointer(s) to the leaves to its immediate left and right. What is the specific advantage in adding those pointers to the leaves in a B+ tree?

By linking the leaves into a linear list, range searches will be more efficient since it will now be necessary to just search for the smallest value that's larger than or equal to the first value in the range and then perform a linear walk across the leaf level until the first value that's too big is located.

In a B-tree, this would require returning to levels above the leaves in order to continue the search.

  1. [9 points] Briefly explain whether using a buffer pool be expected to improve performance in the following situations:

a) application that uses a vector to store a collection of records that are searched repeatedly

There would be no significant advantage; the buffer pool can only significantly decrease the cost of retrieving records from disk. There might be a slight gain however; if the searches exhibit some temporal locality, using a cache to store recently-accessed records could make repeated searches for those records cheaper.

b) application that reads sequentially through a data file to build a vector of records

There would be no advantage; no record would be accessed more than once. Since a sequential pass through the file would exhibit spatial locality (in a very simple way), there would be some merit in retrieving a block of records at once from disk. However, this doesn't need, or benefit from the use of a buffer pool.

c) application that uses a file to store a collection of records that are searched repeatedly

In this case, there is the potential that the buffer pool will lead to improved performance, depending on whether the record searches exhibit enough locality.

  1. A buffer pool implementation uses a fixed number of slots, organized by some simple linear data structure.

a) [8 points] Describe a specific physical data structure that would be a good choice if the replacement policy is FIFO.

The records are removed in the order they are inserted, so this is just a queue. Either an array or a singly- linked list would be appropriate. Since the number of slots is fixed, the linked list would use slightly more memory, but that may be offset by the fact that the array would require extra arithmetic for the circular indexing that would be needed.

b) [8 points] Repeat part a if the replacement policy is least frequently used (LFU).

The record to be replaced is the one with the smallest number of hits. If the records were stored in a poor order, this could require a linear search. So, it would be better to store the records in order of their frequency counts. Since that would require swapping records when frequency counts change, it would be best to do this in a way that didn't require too many copy operations. Therefore, a linked list would be a better choice.