Docsity

Midterm Exam I - Data Structures and Algorithms | CS 240, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
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
),( yxf
. Assume,
0,0 yx
and
a.
1),0( yyf
b.
)1,()0,1( xfxf
c.
)),1(,()1,1( yxfxfyxf
Compute the value of the function
),1( yf
from these definitions.
5. Rank the following functions from low to high (in ascending order) when the variable
parameter n is very large.
a.
nn
b.
3
lg nn
c.
d.
)lgsin(
100
nn
e.
n
n1
f.
nn lglg
g.
n
2
h.
nn lg
5.1
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
pf2

Partial preview of the text

Download Midterm Exam I - Data Structures and Algorithms | CS 240 and more Exams Data Structures and Algorithms in PDF only on Docsity!

Data Structure

CS

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 f^ (^ x , y ). Assume, x  0 , y  (^0) and a. f (^0 , y )^ y ^1 b. f^ (^ x ^1 ,^0 ) f ( x ,^1 ) c. f^ (^ x ^1 , y ^1 ) f ( x , f ( x ^1 , y )) Compute the value of the function f^ (^1 , y ) from these definitions.
  5. Rank the following functions from low to high (in ascending order) when the variable parameter n is very large. a. n n b. n^^ lg^ n^3 c. n n nn^2  n^3 d. sin(^ lg ) n^100 n e. n n

 f. n^ lg^ lg n g. 2 n h. n^1.^5 lg n

  1. 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

Note that you have to show separately which output orders are feasible.

  1. Write a recursive static function equalList (Node p, Node q) that would return TRUE if the two lists headed by the nodes at p and q are identical. If the lists are different, it would return FALSE.
  2. Create an AVL tree with the following nodes inserting them in the order they are presented. You must show your tree after every node insertion and rotation (if any). December, January, April, March, July, August, October, February, September, November, May, June How many rotations of each kind were needed to obtain the final AVL tree? What’s the height of the left subtree of the final tree?
  3. Write a recursive function countSingleChildParent ( ) for a binary tree which would return the total count of number of single child parents in a binary tree.