You are on page 1of 2

National Institute of Technology Rourkela

CS102 Data Structures and Algorithms


Mid Semester Examination, Spring 2017
 UG Sem 2  FM 30  2 Hrs 
 Answer ALL questions  All parts of a question MUST be answered together 
 Mere answers without proper explanation will not fetch marks 
 This question paper contains 2 pages 

1. Let S be a stack of size n ≥ 1. Starting with the empty stack, suppose we PUSH the
first n natural numbers in sequence, and then perform n POP operations. Assume
that PUSH and POP operations take x seconds each, and y seconds elapse between
the end of one such stack operation and the start of the next operation. For m ≥ 1,
derive the stack-life of m as the time elapsed from the end of PUSH(m) to the start
of the POP operation that removes m from S. Derive an expression for average
stack-life of an element of this stack. [4]

2. Suppose a positive integer number is stored using a 2-way linked list, in every node
of which a digit of the number is stored. Write an algorithm to check if the stored
number is a palindrome. [4]

3. Following is a set of simultaneous equations represented in triplet forms of three


sparse matrices. Solve for x, y, and z. [4]
 
3 3 5
   
 1 1 1 
   3 1 3
 [ ]
 
 1 2 2   1 x 
 × 1  3 1 1
   =
 2 2 4   2 1 y  3 1 1
   
 2 3 5  3 1 z
 
3 3 7

4. Write the formula for finding storage location of any non-zero integer in a 2D lower
triangular matrix of size 10 × 10 for both row and column major order. None of
the elements with value zero, in the above matrix, occupy any space. Assume that
indexing starts from 0 for both rows and columns and base address of the memory
starts at 300. What is the storage address of A[3][2] and A[4][1] for both row and
column major order representation of matrix assuming every integer occupies 2
bytes in memory. [3]
2

5. Consider a circular queue Q implemented using an array of 5 elements. Initially Q


is empty. Show the content of Q after each of the following operations :— [4]
(i) Delete(), (ii) Insert(A), (iii) Insert(B), (iv) Delete(),
(v) Insert(C), (vi) Insert(D), (vii) Insert(E), (viii) Insert(F ),
(ix) Insert(G), (x) Delete().

6. Consider a single linked list L1 and a node position n. Deduce an algorithm to


perform the following steps — [4]

(a) Remove the nodes from nth position to 1st position and insert them in a new
linked list L2 in the order they are removed.

(b) Append the remaining nodes of L1 in L2 .

7. Dr. Pradhan is a renowned doctor. He is attended by a maximum of 10


patients daily at his residential chamber. So 10 appointments are received in
first-cum first-serve order. For rest of the requests the patients are informed to
resend on the next day. An appointment is registered on the basis of a pair of
information — (patient’s name, distance between patient’s place and chamber in
kms). A patient coming from the farthest place is asked to attend first, while a
patient staying nearest is asked to attend at last. He consults you for designing
a mobile application to deal with this. Suppose on a particular day the mobile
application receives appointment requests in following order — (A,23), (B,12),
(C,105), (D,1), (G,12), (H,15), (I,33), (J,92), (K,12), (L,200), (M ,5), (N ,250).
How will the mobile application deal with this using a priority queue that can store
upto 10 requests? Show the content of the priority queue after the registration of
each appointment. [4]

8. Convert the following expression to Reverse Polish notation using proper data
structure:
(A ∧ (B ∨ C ∧ ¬D ∨ E) ∨ F ) → G
The following table shows the precedence levels (1: Highest, 4: Lowest)
Operator(s) Precedence level
¬ 1
∧ 2
∨ 3
→ 4
Mention the content of the associated data structure in each step. [3]

You might also like