Answer 2022
Answer 2022
1. MCQ
Group – A
(Multiple Choice Type Questions)
1. Choose the correct alternative for the following: 10 x 1=10
(i) Consider a weighted complete graph G on the vertex set {v1,v2,..vn} such that the
weight of the edge (vi,vj) is 2|i-j|. The weight of a minimum spanning tree of G is
(a) n-1
(b) 2n-2
(c) n/2
(d) n2
(ii) Dijkstra’s Algorithm cannot be applied on
(a) Directed and weighted graphs
(b) Graphs having negative weight function
(c) Unweighted graphs
(d) Undirected and unweighted graphs
(iii) What is the time complexity of counting sort for n number of elements where
the maximum element is m?
(a) O(m+logn)
(b)O(n+logm)
(c)O(log m log n)
(d) None of the above
(iv) Consider the following recurrence equation:
k for n = 1
T(n) =
3T(n/2)+kn for n>1
Which of the following statements is TRUE?
(a) T(n) = O(n1.59) (b) O(1) (c) O(nlog n) (d) None of these
Please do not write questions below this line
Paper setter: ……………………………
(a) 10,8,7,5,3,2,1
(b) 10,8,7,2,3,1,5
(c) 10,8,7,1,2,3,5
(d) 10,8,7,3,2,1,5
(viii Let G be a weighted connected undirected graph with distinct positive edge weights.
) If every edge weight is increased by the same value, then which of the following
statements is/are true?
P: Minimum spanning tree of G does not change
Q: Shortest path between any pair of vertices does not change
(a) P only
(b) Q only
(c) neither P or Q
(d) Both P and Q
(ix) Let S be an NP-complete problem and Q and R be two other problems not
known to be in NP. Q is polynomial time reducible to S and S is polynomial-
time reducible to R. Which one of the following statements is true?
(a) R is NP-complete
(b)R is NP-hard
(c)Q is NP-complete
(d)Q is NP-hard
(x) An array of 30 distinct elements is to be sorted using quicksort. Assume that
the pivot element is chosen uniformly at random. The probability that the
pivot element gets placed in the worst possible location in the first round of
partitioning (rounded off to 2 decimal places) is _________.
(a) 0.03
(b) 0.06
(c) 0.07
(d) 0.04
Group - B
(b) Show that a MAX-HEAP can be built in O(n) time from a given unordered array of n integers.
You need not to write pseudo-code for building a MAX-HEAP. Give the time-complexity analysis
only.
Ans.
h
[(CSEN2201.4) (Analyze/IOCQ)]
(c) Suppose a O(n) time deterministic algorithm is there to find the median of an unsorted array.
Now, consider a QuickSort implementation where the median is first found using the above
mentioned algorithm and then that median is used as pivot. Estimate the worst case time
complexity of this modified QuickSort. Your answer should provide a tight bound. Justify your
answer.
Ans. If we use median as a pivot element, then for each iteration it takes O(n) time to find median
from given function and every time the array partitions in 2 subparts.
so the recurrence equation becomes.
T(n) = 2T(n/2) + O(n)
The above recurrence can be solved using Master Method. It falls in case 2 of master method
which results in complexity O(nlogn).
[(CSEN2201.4) (Analyze/IOCQ)]
(d) Order the following functions by growth rate: N, N2, N log N, N log log N, N1.5, Nlog(N2), 2/N,
2N, 2N/2. Identify the functions with same growth rate (if any).
O(2/N) O(N) O( N log log N) O(N log N)= O( Nlog(N2)) O(N2) O( N1.5) O(2N/2) O(2N)
[(CSEN2201.2) (Understand/LOCQ)]
3 (a) Show that one can sort any 4 numbers given in an array in 5 comparisons.
Ans. Say, the numbers are a,b,c,d. In any comparison greater number is winner and other one is the
loser.
Comparison 1: (a, b)
Comparison 2 : (c, d)
Comparison 3: (Winner of comp1, winner of comp2)
Comparison 4: (Loser of comp1, Loser of comp2)
(b) You are provided as input an even positive integer n > 1 and an unsorted sequence S of n
integers. You would like to find both the second order statistic and the n-th order statistic of S. Show that
they can be found out in exactly 3n/2 + lg n - 3 number of pair-wise comparisons.
Ans. The 1st order statistic (means minimum element) can be found out in (n – 1) comparisons. Now if
you do this as a tournament arranged as a binary tree where as many teams as possible play in the 1st level
and then in the 2nd level etc. then such a tree will have a height of lgn. In other words the champion
(the smallest element) had to play lgn games in order be the champion. If we can track which
numbers were the direct losers to the champion, then the smallest of them is the 2nd order statistic. To find
the minimum of lgn numbers it will take ( lgn -1) more comparisons.
Now you also have to find out the n-th order statistic (maximum element). But if you take (n -1)
comparisons more to find that, then you exceed the given bound. So a small trick is required. Look at the
comparisons that were done at the 1st level in the earlier tournament. How many such comparisons were
there? n/2. Note that the smaller number from each of those comparisons is useless for finding out the n-
th order statistic. So I can now find out the maximum element from the rest of the (n - n/2) elements,
which will take exactly (n - n/2 - 1) = ( n/2 - 1) comparisons (N. B. we do not care in which order they
are compared). Hence total number of comparisons = (n -1) + ( lgn -1) + ( n/2 - 1) = 3n/2 + lgn -
3.
[(CO3) (Understand/LOCQ)]
(c) You have read a proof that the lower bound for comparison sort is Ω(n lg n). But in the last
semester you had been taught some sorting algorithm that ran in O(n) time. What is your
conclusion about this anomaly- there was a mistake in the analysis or something else?
Ans. The sorting algorithm that ran in O(n) time is not comparison based, those were counting
based. [(CO4) (Analyse/IOCQ)]
(2+2) + (6) + (2)….= 12
Group - C
4. (a) Find out an optimal Huffman code for the following set of frequencies, based on the first 6 Fibonacci
numbers.
a:1 b:1 c:2 d:3 e:5 f:8 [(CSEN2201.3) (Apply/IOCQ)]
(b) (i) Fill up the spaces (Asymptotic values are fine) in the following table with respect to Prim’s
algorithm.
How the Priority Queue will be implemented
Array Binary Heap Fibonacci Heap
Each Extract-Min will take O(|V|) O(log|V|) O(log|V|)
Each Decrease-key will take O(1) O(log|V|) O(1)
Final Asymptotic Complexity O(V2+E) O(VlogV+ElogV O(VlogV+E)
)
[(CSEN2201.1) (Remember/LOCQ)]
ii) Now from above you see that there are 3 different options for choosing the data structure to implement
the Priority queue. Which option will turn out to be the best and which one will be the worst for the
following 3 cases – a) E = O(V), b) E = O(V log2 V) and c) E = O(V2)
Ans. a) Best: Binary Heap/Fibonacci Heap, Worst: Array
b) Best: Fibonacci Heap, Worst: Array
c) Best: Fibonacci Heap/Array, Worst: Binary Heap
[(CSEN2201.5) (Evaluate/HOCQ)]
iii) If there is a negative weighted edge in a given graph, will Bellman Ford always be able to give a
solution? [(CSEN2201.1) (Remember/LOCQ)]
(4) + (4.5+3+0.5) = 12
Ans: If there is a negative weighted edge which does not create any negative weighted cycle, then
Bellman-Ford algorithm will always be able to give a solution, but in case it results into a negative
weighted cycle then the algorithm will not be able to give a solution.
5 (a) Compute the Minimum Spanning Tree and its cost for the following graph using Kruskal’s
Algorithm implemented by disjoint set data structure. Indicate each step clearly.
[(CSEN2201.3) (Apply/IOCQ)]
Please do not write questions below this line
Paper setter: ……………………………
(b) Suppose you have n jobs to be performed by a robot. To perform each of them the robot
requires one unit of time. At any point of time, the robot can do only one job. Moreover, if a job
is started, it must be finished before starting the next job. For each i, there is a deadline ti {0,
1, 2, …, n1} associated with the i-th job. If the job is started at a time ti, the robot gets a
(6) + (4+2) = 12
Ans. For each job, there is the associated information: {job ID, deadline, profit}.
The algorithm goes as follow:
Group - D
6 (a) TABLE_INSERT(T, x)
1. if size(T)=0
2. then allocate tab[T] with 1 slot
3. size[T] 1
4. if num[T] = size[T]
5. then allocate new-table with 2. size[T] slots
6. insert all old items to new-table
7. free tab[T]
8. tab[T] new-Table
9. size[T] 2. size[T]
10. insert x into tab[T]
11. num[T] num[T] + 1
Using accounting method, calculate the amortized cost of each TABLE_INSERT operation.
[(CSEN2201.4) (Analyze/IOCQ)]
Ans. Accounting Method:
Amortized cost of a TABLE_INSERT is 3 for inserting itself into the current table, moving itself when the
table expands, and moving another item that has already been moved once when the table expands.
For example, suppose that the size of the table is m immediately after an expansion. Then the table
holds m/2 items, and it contains no credit. We charge 3 dollars for each insertion. The elementary
insertion that occurs immediately costs 1 dollar.
(b) Draw state-transition diagram for the string-matching automaton that accepts all strings ending in
the string abbababbabbaba. [(CSEN2201.3) (Apply/IOCQ)]
Accounting method
Actual Cost:
i-th operation =i, i=2k,
=1, otherwise
Amortized cost :
For each operation cost =3,
(b) Write a short note on Skip List. Show that the expected space usage of a skip list with n items
is O(n). [(CSEN2201.2) (Understand/LOCQ)]
Ans. A skip list for a set S of distinct (key, element) items is a series of lists S0, S1 , … , Sh such
that
Each list Si contains the special keys + and -
List S0 contains the keys of S in nondecreasing order
Each list is a subsequence of the previous one, i.e.,
S0 S1 … Sh
List Sh contains only the two special keys
It uses a randomized insertion algorithm
In a skip list with n entries
The expected space used is O(n)
The expected search, insertion and deletion time is O(log n)
Group - E
8 (a)
Using Ford Fulkerson algorithm, find out the amount of maximum flow of the above flow network.
[(CSEN2201.3) (Apply/IOCQ)]
(b) Say there are two disjoint sets: {1, 2, 100} and {5, 78, 90}.
Draw two diagrams to compare between linked list representation and rooted tree representation
of the above two sets. Also show how these data structures will be modified after the UNION
operation. [(CSEN2201.2) (Understand/LOCQ)]
Ans.
9 (a) Prove that the Clique Decision problem is NP-hard by using the result that the 3-CNF-SAT
problem is computationally hard. [(CO5) (Assess/HOCQ)]
(b) (i) Fill in the gap:-“No constant approximation algorithm exists for a general TSP.”
[(CO1) (Remember/LOCQ)]
(ii) Give a 2-approximation algorithm for a TSP that satisfies triangle inequality and give a brief
proof that it indeed maintains the approximation ratio.
[(CO5) (Assess/HOCQ)]
(6) + (0.5+(3.5+2)) = 12
Course Outcome:
*LOCQ: Lower Order Cognitive Question; IOCQ: Intermediate Order Cognitive Question; HOCQ: Higher Order Cognitive Question