final sem 24
final sem 24
Comprehensive Examination
(EC-3 Regular)
Q-1 Taarak Mehta’s boss tries to confuse genius Taarak. Boss asks Mr. Mehta to write an algorithm 5
whose time complexity is as follows. Marks
T(n) = T(n - 1) + T(n - 2) + O(n)
Q-2 Prof. Virus has a single linked-list of students’ names. He asked Rancho to bring all odd- 5
positioned names together and even-positioned names together. Prof. Virus restricted Rancho Marks
from using any additional data structure. However, he is free to use additional pointer variables
to linked list nodes. He also instructed that the sequence of students at odd positions must be
same as input list. Similarly, the sequence of students at even positions must be same as input
list. Header to the linked list is given. Write the complete algorithm “Rancho” as your answer. In
the following sample inputs/outputs are given for your understanding. However, your algorithm
must work for all possible inputs.
Sample input1:
Raju → Rancho → Farhan → Pia → Chatur
Sample output1:
Raju → Farhan → Chatur → Rancho → Pia
Sample input2:
Raju → Rancho → Farhan → Pia → Chatur → Milli
Sample output2:
Raju → Farhan → Chatur → Rancho → Pia → Milli
Algorithm Rancho(header)
curr1 ← header
if curr1 = NULL then
Print “List empty”
Exit
end if
//Complete the algorithm
Q-3 Prof. Bhide gave a stack containing a string to Tapu and asked him to write an algorithm that 5
considers ‘*’ as backspace and gives the final output. Prof. Bhide restricted Tapu from using any Marks
additional data structure. However, he is allowed to use such variables that can store only one
value. He gave a hint that write the algorithm in a recursive manner. Write the complete Support
algorithm as your answer. In the following sample input/output is given for your understanding.
However, your algorithm must work for all possible inputs.
Sample input: BIT*SPILAN*IW (top of the stack pointing to W)
Sample output: BISPILAIW (top of the stack pointing to W)
Note: Assume that * will not be there at the start or end of the input string and * will not be there
in consecutive places in the input string.
Algorithm push(s,o):
top ← top+1
s[top] ← o
Algorithm pop(s):
if top = 0 then
Print “stack-empty”
Exit
end if
e ← s[top]
s[top] ← NULL
top ← top - 1
return e
Algorithm Tipendra(string x)
for i = 1 to x.length do
push(s,x[i])
Support()
Algorithm Support(s)//String characters are already pushed in stack ‘s’
//Complete the algorithm
Q-4 Prof. Forget has a map of the school. This map contains vertices as classrooms and edges as 5
energy required to go from one classroom to another classroom. Prof. gave a map to you and Marks
asked you to visit all the classes to announce that exam will be conducted tomorrow. You do not
want to spend too much energy on this task due to these summer days. Apply Kruskal’s
algorithm, show derivation as per the following table, and find the minimum energy required to
visit all the classrooms.
Steps Edges considered/rejected Connected components
… … …
… … …
Q-5 Prof. Forget fell asleep while writing the Merge sort algorithm. He made two mistakes in writing 5
the merge algorithm as underlined. He wants to see the effects of these mistakes on the output of Marks
the quick sort algorithm for the input array arr = {7, 16, 7, 14, 13, 20, 15, 2, 5}. Write the output
array only as your answer.
Q-6 Apply Dijkstra’s algorithm on the following graph by considering vertex ‘6’ as the source. As 5
per the following table, write the set of labels for each vertex, where the label contains (previous Marks
vertex, distance).
5 (6, 250)
6 (-,0)
Q-7 During summer days, Harry and his friends are playing on the stairs of Hogwarts University. 10
They are able to climb 1/2/3 steps during each jump. Prof. Dumbledore saw them. In place of Marks
stopping them, Prof. gave them the following task for their betterment. He asked Harry and his
friends to derive an algorithm to find the minimum number of jumps required to climb the stairs
using dynamic programming. Write the algorithm solution as your answer.
E.g., If the stair has 9 steps, one can climb the stair with 3 jumps (i.e., 3 steps + 3 steps + 3 steps)
******