
Data Structure
CS240
Midterm exam
Fall 2004
Answer only 5 questions from below.
1. A fraction is a mathematical object that has an integer numerator and an integer
denominator. Given this definition, describe an ADT for a class of objects fraction.
Indicate at least five methods that could be called on such an object.
2. Compare and contrast a linear list implemented as (a) an array, (b) a sequential file like
java stream, and (c) a linked linear list. Compare them on the following attributes: (a)
ease of access, (b) storage, (c) insertion/deletion, and, (d) object update.
3. Consider the following generalized list L = ( (a) b). What sequence of operations must be
performed on L so as to transform it to a list ((b) a )? Outline the corresponding set of
operators in the order they must be applied to get the desired transformation.
4. Consider the following recursive definition of a function
. Assume,
and
a.
b.
c.
)),1(,()1,1( yxfxfyxf
Compute the value of the function
from these definitions.
5. Rank the following functions from low to high (in ascending order) when the variable
parameter n is very large.
a.
b.
c.
d.
e.
f.
g.
h.
6. Suppose the data items numbered 1, 2, 3, 4, 5, 6 come in the input stream in this order.
That is, 1 comes first, then 2, and so on. By using an inputrestricted deque which of the
following rearrangements can be obtained at the output stream? The entries also appear in
the output in left-to-right order. Note that at any time you could output an item if this is
necessary and legally done.
a. 4 2 1 3 6 5 b. 2 4 3 6 5 1
c. 1 2 6 4 5 3 d. 5 2 6 4 3 1