Test I Questions - Data Structures and Algorithms | CS 240, Exams of Data Structures and Algorithms

Material Type: Exam; Professor: Sengupta; Class: Data Structures & Algorithms; Subject: Computer Information Science; University: SUNY Institute of Technology at Utica-Rome; Term: Fall 2004;

Typology: Exams

Pre 2010

Uploaded on 08/09/2009

koofers-user-fkt
koofers-user-fkt 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Test 1 (Supplementary)
Data Structure
CS-240
Fall 2004
Answer only 5 questions from below
1. Describe an ADT Priority_Queue which is like a queue we are all familiar with but has additional
structures in it. For instance, each object queuing in it would have a priority value (an integer)
which we assume to be a constant. The queue discipline will not be FIFO (or FCFS) but it would
be priority-driven; the object with highest priority gets out first from such a queue. In your ADT
identification, include at least 5 methods that could be called in a public mode.
2. Consider the following code:
static void pattern(int level) {
if (level == 0) {
System.out.print("*");
}
else {
System.out.print("[");
pattern(level - 1);
System.out.print(",");
pattern(level - 1);
System.out.println("]");
}
}
What would be the output for the following calls: (a) pattern(0), (b) pattern(1),
(c) pattern(2), and (d) pattern(3)
3. We are interested in estimating computational time of a program code. We assume that every
assignment, every arithmetic operation, every logical comparison consumes on an average one
unit of CPU time. Given this, compute the minimum time required to run the following code on a
machine with a single CPU. We assume that the variable n is known in the program.
...
int sum=0;
for (int i=1; i<n; i=2*i)
{
System.out.print(i+" ");
sum +=i;
if (i%2 == 0){
sum=sum*3;
sum=sum-1;
}
}
System.out.println();
System.out.println(sum);
Furthermore, indicate how the result will change if the for loop is changed to
for (int i=0; i<n; i=2*i)
pf2

Partial preview of the text

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

Test 1 (Supplementary) Data Structure CS- Fall 2004 Answer only 5 questions from below

  1. Describe an ADT Priority_Queue which is like a queue we are all familiar with but has additional structures in it. For instance, each object queuing in it would have a priority value (an integer) which we assume to be a constant. The queue discipline will not be FIFO (or FCFS) but it would be priority-driven; the object with highest priority gets out first from such a queue. In your ADT identification, include at least 5 methods that could be called in a public mode.
  2. Consider the following code: static void pattern(int level) { if (level == 0) { System.out.print("*"); } else { System.out.print("["); pattern(level - 1); System.out.print(","); pattern(level - 1); System.out.println("]"); } } What would be the output for the following calls: (a) pattern(0), (b) pattern(1), (c) pattern(2), and (d) pattern(3)
  3. We are interested in estimating computational time of a program code. We assume that every assignment, every arithmetic operation, every logical comparison consumes on an average one unit of CPU time. Given this, compute the minimum time required to run the following code on a machine with a single CPU. We assume that the variable n is known in the program. ... int sum=0; for (int i=1; i<n; i=2i) { System.out.print(i+" "); sum +=i; if (i%2 == 0){ sum=sum3; sum=sum-1; } } System.out.println(); System.out.println(sum); … Furthermore, indicate how the result will change if the for loop is changed to for (int i=0; i<n; i=2*i)
  1. Rank the following functions in ascending order:

a. n 1.^500001 lg(n^64 ) b. 2. 5

1. 5 18

3 n

6 n  ncos(n )  2 n

c.

n

nlg( n

lg( n

d. n n^3 e. 7  e ^3 n f. n^ lglg^ n^4 g. n

n

  1. Suppose that a linked list is formed from objects that belong to the class class Node{ int item; // an item appearing in the node Node next; // reference to the next item in the list } Write an iterative function that will find the sum of all the items in a linked list over all such nodes.
  2. Write a recursive function that will take a linked list and convert it to a reversed list. For instance,

if the original list were 1  3  5  7  9 the function will convert it to the list

  1. Assume L is a generalized nonlinear list and it is posted as L = (((a ((b (c))))))

Draw a sketch of this list. Let O 1 (L)  c and O 2 (L)  b. Find the operators

O 1 and O 2 , respectively. How would you construct the list (((c)))?

  1. Assume you have a preorder traversal and an inorder traversal of a specific binary tree posted as shown. Using these two traversals draw the original binary tree which, in your opinion, would yield these two traversals. PRE: h i g a f b l c j e d k IN: i h a l j c b f e k d g What is the height of its right-subtree?
  2. Suppose the following alphabets occur normally with the relative frequencies as shown. Using this information, develop Huffman codes for each of these alphabets. In the coding tree, use the convention of attaching a 0 on every left branch and 1 to every right branch of the tree that you would generate. Symbol g o space e s h p r Frequency 3 3 2 1 1 1 1 1 To what word does the bit string 10110100010101100111 translate?
  3. Write a recursive function that will return the number of nodes having only a right child. These are single child parents and the child must be a right child as opposed to a left child.