Final Sem 23
Final Sem 23
Comprehensive Examination
(EC-3 Regular)
Q-1 Determine the value of x and y (in terms of n) at the end of the execution of the 10 Marks
(Set A) following algorithms algo1 and algo2. (5 marks + 5 marks)
(Note: Partial marking will not be done for this question.)
Q-3 Prof. Forget used to make tricky questions for students. He gave prefix traversal 10 Marks
(Set B) sequence + + a * b c * d + e f for a tree of an expression. He also gave a formation of
this tree with labels {L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11} as follows.
(a) If x = 10, y = 20, z = 30, and w = 40, then identify the value after evaluating this
expression. (5 Marks)
(b) Identify the values of labels L1 = __, …, L11 = __. (5 Marks)
(Note: Partial marking will not be done for this question.)
Q-4 Sometimes students challenge Prof. Forget by writing a faulty algorithm. A student 10 Marks
(Set A) wrote two algorithms for checking balanced parentheses and challenged Prof. Forget to
find input strings for which her algorithms give wrong output. You need to write one
input string for algorithm Parenthesis1 and one input string for algorithm Parenthesis2
as your answer. (5 marks + 5 marks)
(Note: Partial marking will not be done for this question.)
Algorithm Parenthesis1 (IP) Algorithm Parenthesis2 (IP)
//IP is a string of parenthesis //IP is a string of parenthesis
//S is stack that is initially empty //S is stack that is initially empty
for i = 1 to IP.length do for i = 1 to IP.length do
if IP[i] = '(' then if IP[i] = '(' then
PUSH(S, IP[i]) PUSH(S, IP[i])
else if IP[i] = ')' AND else if IP[i] = ')' OR
Stack.empty( ) = FALSE Stack.empty = FALSE
POP(S) POP(S)
else else
PRINT("Unbalanced") PRINT("Unbalanced")
Exit Exit
PRINT("Balanced") PRINT("Balanced")
Q-4 Ms. Neha is learning recursive algorithms. She made the following algorithms for stack 10 Marks
(Set B) and queue data structures. Find out the values in stack and queue after executing the
following algorithms on the given stack and queue. You need to write values of stack
and queue with values of top of the stack, front-rear of the queue as your answer.
(5 marks + 5 marks)
(Note: Partial marking will not be done for this question.)
Use Prim's algorithm to find minimum spanning tree for Mr. Porter to cover all rooms
with minimum energy. Assume that you starts with odd hours and require exact 1 hour
to find a minimum edge. Assume that starting vertex for Prim's algorithm is 0.
As your answer, you need to write the sequence of edges chosen during execution of
Prim's algorithm and the total minimum energy requirements to visit all the rooms.
Q-6 A mathematician came to Prof. Forget for solving a large binomial coefficients using 30 Marks
(Set A) algorithms. He gave the following formula to Prof. Forget for solving the problem.
BC(n, k) = 0 (if k > n)
or = 1 (if k = 0 or k = n)
or = BC(n-1, k-1) + BC(n-1, k) (Otherwise)
Prof. Forget made the following recursive algorithm for the same. But he is not happy as
this algorithm computes the same BC(i, j) multiple times as shown in below table.
He asked you to devise an algorithm using dynamic programming. You need to write
formula of dynamic programming for this problem (6 marks), algorithm using dynamic
programming (12 marks), and derivation matrix of BC(4,2) using your algorithm (12
marks). (Hint: Recall Fibonacci Problem using dynamic programming).
Q-6 Prof. Bhide gave a tough question paper for a given time limit. Tapu went through the 30 Marks
(Set B) question paper and noted marks and no. of minutes required to solve the each question.
Tapu gave this note to you and asked to get the sequence of questions numbers for
scoring as much as possible.
(a) You need to write an algorithm using dynamic programming to find such sequence
of question numbers (15 marks).
(b) You need to write matrix (5 marks), possible maximum marks (5 marks), and
sequence of question numbers to be attempted (5 marks) using your algorithm for the
following input. Assume that maximum time for test is 10 minutes.
Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7
Time 1 1 2 3 3 4 5
required
Marks 5 8 4 9 10 7 15