Sei sulla pagina 1di 2

VIT

UNIVERSITY
(Estd. u/s 3 of UGC Act 1956)

School of Computing Sciences


Continuous Assessment Examination, August 2007
Course

: B.Tech

Subject
Duration

Branch: CSE

Semester

: III

: Data Structures and Algorithms

Batch

: A, B, C, D, E

: 90 Min

Max. Marks : 50

Part A

10 X 2 = 20

1) Suppose that algorithm A takes 1000n3 steps and algorithm B takes 2n steps for a problem of size n.
For what size of problem is algorithm A faster than B?
2) Write an ADT to describe a dictionary?
3) Determine the complexity of the following block of code
a) for( i = 0 ; i < n ; i++)i
for( j = 0 ; j <= i; j++)
for( k = 0 ; k <= j; k++)
x++;
b) i = 1;
while( i <= n)
x++; i++;
4) Order the following functions by their growth rates. Indicate the direction of growth!
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)

n log 144 + 123 log n


12n
n! log n
4 log n
n!
2 log n
2n-3
16n-177

5) Let A be an array consisting of n integers and x an integer. The function IsMember() gets an input A
& x and returns true when x appears in A, false otherwise. Write a simple code block for IsMember
Function and analyse its worst case complexity
6) How would you implement a queue of stacks?
7) Convert the following infix expression into postfix form( Considering C++ Precedence )
(a) ( a + b ) * d + e / ( f + a * d ) + c
(b) a && b || c || ! ( e > f )

8) Can a template be used to store elements of different data types on the same stack? Why or why not??
9) Give a situation where memory compaction has to be done?
10) Write a simple function to add two polynomials.
[ PTO]

Part B

3 X 10 = 30

11) (a) Three students suggested three different algorithms for the same problem. The performances
of their algorithms are given below.
Case 1: n = 10
Run time for student 1: 1
Run time for student 2: 1 / 100
Run time for student 3: 1 / 1000
Case 2: n = 100
Run time for student 1: 10
Run time for student 2: 1
Run time for student 3: 1
(i) Find the complexity of the three algorithms using Big Oh.

(2 Marks)

(ii) Say which algorithm is the best and which is the worst?

(1 Mark)

(iii) Suggest some value of n at which the best algorithm performs better than the other
algorithms?
( 2 Marks)
11. (b) Will all the recursive algorithms give logarithmic complexity? Justify your answer by writing
a recursive procedure to find the sum of first n natural numbers.
(5 Marks)

12) (a) For each of the following statements, decide whether it is always true, never true, or
sometimes true for asymptotically nonnegative functions f and g. If it is always true or
never true, explain why. If it is sometimes true, give one example for which it is true, and
one for which it is false.
(6 Marks)
(a) f(n) = O(f(n)2)
(b) f(n) + g(n) = (max (f(n), g(n)))
(c) f(n) + O(f(n)) = (f(n))
12. (b) In a library management system, you are asked to develop an student entry monitoring system
which does the following.
When a student enters the library, the Registration Number and the time of entry must be
stored and When a student leaves out, find the duration he spent in library for that particular
student and display it.
Which data structure you will use? Justify your answer?

(4 Marks)

13) Write the pseudo code to split a doubly linked list into two separated doubly linked lists. The
elements in odd positions must remain in the original linked list and the elements in even positions
are inserted into a new linked list .The elements should retain their same relative order. Draw the
diagram for each operation.
(10 Marks)

Potrebbero piacerti anche