You are on page 1of 2

 II sem, UG  End Semester Exam  Spring–2017  CS102 (DSA)  50 Marks  Time 3hrs 

Answer ANY FIVE out of eight questions. Each question should be answered with adequate explanation. Figures next to
each question in square bracket indicate marks. All parts of a question must be answered at one place.
This question paper contains two pages.

1. Answer the following considering the mathematical expression: (a + b)/((c − d) ∗ (e − f))


(a) Find if there is mismatched parenthesis in the above expression using stack.
(b) Convert the above expression to reverse Polish notation using stack.
Show all the intermediate steps of your procedure clearly. [5+5]
2. (a) What is the disadvantage of grounded linear queue?
How to overcome this disadvantage?
Define queue as an Abstract Data Type.
(b) Consider two queues: one linear grounded queue, and one circular queue, each of size 20 implemented using arrays
LQ[20] and CQ[20] respectively. The array indexing in LQ and CQ starts from 0. The REAR and FRONT indices of both
LQ and CQ are initialized to -1. Twenty deletion operations are carried out one at a time in both the queues after the
queue has become full by 20 sequential insertion operations. Every deletion operation in LQ follows a left shift operation
of every existing element in the queue to accommodate a space in the right side. Every deletion operation in the CQ
does not perform any left shift operation. If each left shift operation in LQ takes 2 time units, find the total savings of
time units using CQ as compared to 20 deletion operations in LQ. Illustrate each computational step showing the front,
rear values and number of current elements in LQ. What will be the asymptotic computational complexity for the total
number of time units required due to left shift operations in LQ when the queue size is N and every left-shift operation
takes k time units. [(1+1+2)+6]
3. (a) Insert the alphabets A L G O R I T H M in sequence into an initially empty AVL tree.
(b) Delete nodes A, L, M from the constructed AVL tree.
(c) What is the worst case time complexity for performing LR type of rotation? Why? [4+4+2]
4. (a) In the Table below, what sequence of ‘middle’ values are compared with the key when performing a binary search with
target doughnut?
(b) In the Table below, what sequence of ‘middle’ values are compared with the key when performing a binary search with
target tiramisu?
(c) Apply merge-sort to sort the list E, X, A, M, P, L, E in alphabetical order. [3+3+4]
index value index value index value
0 babka 5 eclair 10 sopaipilla
1 baklava 6 funnelcake 11 strudel
2 cheesecake 7 kringle 12 tiramisu
3 cupcake 8 lamington 13 torte
4 danish 9 profiterole 14 turnover

5. (a) State the superiority of Bellman–Ford algorithm over Dijkstra’s algorithm.


(b) The pseudo code for depth first search (DFS) mentioned below traverses a graph G from the source vertex s in an
iterative manner. Compute the total units of time that would be consumed for traversing the graph shown in Figure 1
with ‘A’ as the source vertex. While computing the total time, deduce the time consumed at each step of the iteration
and show them clearly in your answer along with adequate explanations. Note that push and pop operations consume
unit time each. Each time a vertex is visited it is added to a “Visited List”, which is a singly linked list. Insertion in
this list takes place only at the beginning. AA b2K- l: 1M/ a2K2bi2` 1tK aT`BM;ĜkyRd *aRyk U.aV
[2+8] 8y

R 6mM+iBQM Bi2`iBp2.6aUG, sV
ff q?2`2 G Bb  ;`T? M/ s Bb i?2 bQm`+2 p2`i2t
k G2i S #2 bi+Fc
j S.push(s)cff Smb? s BMiQ i?2 bi+F S
9 // s iQ  pBbBi2/ HBbic
A B
ff oBbBi2/ HBbi Bb KBMiBM2/ b  bBM;Hv HBMF2/ HBbi r?2`2
ff BMb2`iBQM Bb T2`7Q`K2/ QMHv i i?2 #2;BMMBM;X
C D E F 8 r?BH2 S Bb MQi 2KTiv /Q
e v = S.pop()c
ff SQT  p2`i2t 7`QK bi+F S iQ pBbBi M2ti
G H d 7Q` HH M2B;?#Qm`b w Q7 v BM G /Q
ff Smb? HH M2B;?#Qm`b Q7 p BM bi+F i?i `2 MQi pBbBi2/
Figure 1: Graph with 8 vertices 3 *?2+F r?2i?2` w Bb pBbBi2/ Q` MQic
N B7 w Bb MQi pBbBi2/ i?2M
Ry S.push(w)c
RR K`F w b pBbBi2/c

1
 II sem, UG  End Semester Exam  Spring–2017  CS102 (DSA)  50 Marks  Time 3hrs 
6. (a) Let G be connected undirected graph of 100 vertices and 320 edges. The weight of a minimum spanning tree of G is
860. When the weight of each edge of G is increased by three, what will be the weight of a minimum spanning tree?
(b) Consider the following adjacency matrix for graph G1 . How many sequences (Mention them) can be attained to achieve
a minimal spanning tree by using Kruskal’s Algoritihm?
 
3 1 6 0 0 0
1 0 3 4 0 2
 
6 3 0 2 4 7
G1 = 
0

 4 2 2 3 1
0 0 4 3 0 5
0 2 7 1 5 0

(c) The graph shown below (Figure 2) has 8 edges with distinct integer edge weights. The minimum spanning tree (Using
Prim’s Algorithm starting from A) is of weight 36 and contains the edges: (A, C), (B, C), (B, E), (E, F), (D, F). The
edge weights of only those edges which are in the MST are marked. What is the minimum possible sum of weights of all
8 edges of this graph? Note that each edge has distinct weight. [2+4+4]

B E 4
15
A 2 F
9 6
C D

Figure 2: Graph with six vertices

7. (a) Let A be a 4 × 4 matrix as follows — (b) Let number be an array that stores only the positive
  integers 23, 99, 500, 1000, 740, 165, 800, 263, 119, 465.
9 18 27 36 What will be the outcome of the following module?
4 8 12 16
A= 2 4

6 8
5 10 15 20 Num1 =0
Num2=0
Mention the expected output of the following code while for k = 1 to 10 do
implemented on the matrix. {
If (number [k] > Num1)
C = 100 {
for i = 1 to 4 do Num2 = Num1
for j = 1 to 4 do Num1= number [k]
{ }
Temp = A[i] [j] + C Else
A[i] [j] = A[j] [i] If (number [k] > Num2)
A[j] [i] = Temp - C {
} Num2=number[k]
for i = 1 to 4 do }
for j = 1 to 4 do }
Output (A[i] [j]) Display (Num1, Num2)

(c) Add the given two polynomials using linked list:

4x3 + 3x5 + 7x − 1
and
2x4 − 6x3 + x2 + 6

[2.5+2.5+5]
8. (a) Insert the elements 5 7 1 9 6 0 4 10 3 2 into an initially empty m-way search tree with m = 3.
Show each intermediate step clearly with justification.
(b) Post-order traversal of a binary search tree yields 2 6 4 9 11 14 16 12 10.
Can the tree be reconstructed from this information?
If no, justify why?
If yes, derive the reconstructed tree. [5+5]

You might also like