0% found this document useful (0 votes)
11 views14 pages

Answer 2022

The document outlines guidelines for marking answers and includes a series of multiple-choice questions related to algorithms and data structures. It covers topics such as minimum spanning trees, sorting algorithms, and the complexities of various operations. Additionally, it includes problem-solving tasks involving the Master theorem, job scheduling algorithms, and amortized analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Answer 2022

The document outlines guidelines for marking answers and includes a series of multiple-choice questions related to algorithms and data structures. It covers topics such as minimum spanning trees, sorting algorithms, and the complexities of various operations. Additionally, it includes problem-solving tasks involving the Master theorem, job scheduling algorithms, and amortized analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

 Part marking is must for each question and it should be given on the left hand side of the answer

script. At the end of answer to a question total marks should be encircled.

1. MCQ

Question Number Correct Option


i) b
ii) b
iii) d
iv) a
v) c
vi) b
vii) d
viii) a
ix) b
x) c

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: ……………………………

Moderator : ……………………………… Page 1


(v) The tightest lower bound on the number of comparisons, in the worst case, for
comparison-based sorting is of the order of
(a) N (b) N^2 (c) NlogN (d) N(logN)^2
(vi) Merge procedure in Merge sort takes
(a) O(nlogn) time (b) O(n) time
(c) O(1) time (d) None of the mentioned
(vii) A priority queue is implemented as a max-heap initially, it has five elements. The
level-order traversal of the heap is as follows:
10, 8, 5, 3, 2
Two new elements '1' and '7' are inserted in the heap in that order, The level-order
traversal of the heap after the insertion of the element is

(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

2 (a) Solve using Master theorem


T(n) = 7T(n/2)+ n2 [(CSEN2201.4) (Analyze/IOCQ)]
Ans. a = 7, b = 2, nlog b(a)=n2.807
Please do not write questions below this line
Paper setter: ……………………………

Moderator : ……………………………… Page 2


f(n) = n2
f(n) = O(n2.807-.807) = O(nlog b(a)-.807)
As 0.807 is a positive quantity, it falls in Case 1 of Master Theorem. So the answer would be
T(n) = Θ(nlog b(a))

(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, N2, 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(N2) O( N1.5) O(2N/2) O(2N)
[(CSEN2201.2) (Understand/LOCQ)]

(3) + (3) + (1+3) + (2) = 12

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)

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 3


Comparison 5: (Loser of comp3, Winner of comp4)
The ordering would be: Winner of comp3>winner of comp5>Loser of comp5>Loser of comp4.
For 5 numbers (the last number is e), additionally following comparison would be needed:
Comparison 6: (e, Loser of comp5)
If e is the winner, we need 2 more comparisons.
If e is the loser, we need 1 more comparison.
So in the worst case we need 8 comparisons.
[(CO2) (Remember/LOCQ)]

(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)]

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 4


Ans:

(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: ……………………………

Moderator : ……………………………… Page 5


Ans.

(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, …, n1} associated with the i-th job. If the job is started at a time  ti, the robot gets a

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 6


profit of pi (a positive integer). If the job is started at time > ti, there is no profit at all. This
means if a job cannot be scheduled on or before its starting deadline, the job need not to be
scheduled at all. Notice that the deadlines may not be distinct from one another. You need to
select and schedule a subset of the jobs for the robot in such a way that the robot’s profit is
maximized. Propose an O(n log n) time greedy algorithm to solve this problem. Analyze that
your algorithm has the given running time. [(CSEN2201.6) (Design/HOCQ)]

(6) + (4+2) = 12
Ans. For each job, there is the associated information: {job ID, deadline, profit}.
The algorithm goes as follow:

Sort the jobs based on their deadlines (in non-decreasing order).


Iterate from the end (i.e. from the job with highest deadline) and calculate the
available slots between every two consecutive deadlines. Include the profit,
deadline, and job ID of ith job in the max heap.
While the slots are available and there are jobs left in the max heap, include the
job ID with maximum profit and deadline in the result.
Sort the result array based on their deadlines.
1. Sorting of the jobs can be performed in O(n log n) time.
2. Building Max Heap will take O(n log n).
3. Extract max will be performed at most n times. O(n log n)
4. Sorting the resultant array based on their deadlines will be performed in O(n log
n).

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)]

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 7


Ans.
(c) State the asymptotic time complexity of the KMP algorithm used for pattern matching and remember
to define the terms you use. [(CSEN2201.1) (Remember/LOCQ)]
(6) + (5) + (1) = 12
Ans. O(m+n), where m is the length of the pattern and n is the length of the text.

7 (a) Suppose we perform a sequence of n operations on a data structure in which the i th


operation costs i if i is an exact power of 2, and 1 otherwise. Use aggregate analysis and
accounting method to determine the amortized cost per operation.
[(CSEN2201.3) (Apply/IOCQ)]
Ans. Aggregate Analysis

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 8


ADD 2023

Accounting method
Actual Cost:
i-th operation =i, i=2k,
=1, otherwise
Amortized cost :
For each operation cost =3,

Total amortized cost for n operation = 3n=O(n)


As total credit is always non-negative, total amortized cost is the upper bound of total actual cost.
So total actual cost = O(n). So actual cost per operation = O(1).

(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)

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 9


(6) + (3+3) = 12

Group - E

8 (a)
Using Ford Fulkerson algorithm, find out the amount of maximum flow of the above flow network.
[(CSEN2201.3) (Apply/IOCQ)]

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 10


Ans:

(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.

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 11


(6) + (3+3) = 12

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)]

• Ans. Find the maximum sized clique from a graph


• The corresponding decision problem called clique decision problem (CDP) is NP-Complete
• CNF satisfiability is NP- Complete by Cook-Levin theorem.
• Karp reduced CNF-Sat to CDP.
• CNF formula(f)  Graph (G)
• It has a vertex for every pair (v, c).
• v is a variable or its negation (v’),
• c is a clause in the formula f that contains v.
• Edges are there between (v, c) and (u, d) if , c ≠ d and u ≠ v’
• Means: between any 2 literals in different clauses, who are not each other’s negation.
• If k denotes the no. of clauses in the CNF formula (f), then the k-vertex clique in the
graph represents ways of assigning truth values to some of its variables in order to
satisfy the formula.
• f is satisfiable iff a k-clique exists.

(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.

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 12


Ans.
Proof- T is the MST and H* is the cost of the optimal tour.
c(T) <= c(H*). Why? We obtain a spanning tree by deleting any edge from a tour, and each edge cost
is nonnegative. Therefore, the weight of the minimum spanning tree T provides a lower bound on
the cost of an optimal tour.
• A full walk W of MST T traverses every edge of T exactly twice, we have, c(W) = 2*c(T)
It implies, c(W) <= 2*c(H*)
• Unfortunately, the full walk W is generally not a tour, since it visits some vertices more than
once.
• By the triangle inequality, however, we can delete a visit to any vertex from W and the cost
does not increase. By repeatedly applying this operation, we can remove from W all but the
first visit to each vertex
• This ordering is the same as that obtained by a preorder walk of the tree T. Let H be the
cycle corresponding to this preorder walk.
• It is a hamiltonian cycle, since every vertex is visited exactly once, and in fact it is the cycle
computed by APPROX-TSP-TOUR.
• Since H is obtained by deleting vertices from the full walk W , we have c(H) <= c(W)
• It implies c(H) <= 2c(H*), which completes the proof.

[(CO5) (Assess/HOCQ)]
(6) + (0.5+(3.5+2)) = 12

Cognition Level LOCQ IOCQ HOCQ


Percentage 23.44 55.21 21.35
distribution

Course Outcome:

After the completion of the course students will be able to

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 13


………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………

*LOCQ: Lower Order Cognitive Question; IOCQ: Intermediate Order Cognitive Question; HOCQ: Higher Order Cognitive Question

Please do not write questions below this line


Paper setter: ……………………………

Moderator : ……………………………… Page 14

You might also like