MTE Solution Sketch and Grading Policy
MTE Solution Sketch and Grading Policy
MTE Solution Sketch and Grading Policy
1
2. Answer exactly ONE of the following TWO questions: Maximum Marks: 15
(Aa) Multistacks. Consider a multistack, i.e., an infinite series of stacks S0 , S1 , S2 , · · ·, the capacity of
Si is 3i . For any full stack Si , an element is pushed by popping all its elements and pushing them
on Si+1 before the push. Similarly, for any empty stack Si , an element is popped by popping 3i
elements from Si+1 and pushing them onto Si before the pop. Prove that for any sequence of n
push and pop operations on S0 , the amortized time for each operation is O(log n).
Grading Policy. No explicit grading policy. Deduct marks based on mistakes.
(Ab) Palindrome Swaps. Given n strings, each of length m having lowercase english letters. A
swap operation swap(i, j) (where i ∈ [1, n], j ∈ [1, m]) swaps the j th character of Si with the j th
character of Si+1 . Design and analyze an algorithm to compute the minimum number of swaps
to convert every string into a palindrome.
Grading Policy. Marks Distribution:
i. [12 Marks] Algorithm,
ii. [3 Marks] Analysis.
iii. Deduct 80% marks if ω(mn log n) algorithm given.
(Ba) Closest Pair of Points. Given a set of n points in a 2D plane, describe and analyze an algorithm
using divide and conquer strategy to compute the closest pair of points.
Grading Policy. Marks Distribution:
i. [10 Marks] Algorithm,
ii. [5 Marks] Analysis.
iii. Deduct 80% marks if ω(n log2 n) algorithm given and 60% if Θ(n log2 n) given.
(Bb) Median of Medians. Given an array of n numbers, describe and analyze the pick algorithm to
compute the k th ranked number in the sorted array in linear time.
Grading Policy. Marks Distribution:
i. [10 Marks] Algorithm,
ii. [5 Marks] Analysis.
iii. Deduct 80% marks if ω(n) algorithm given.
3. Answer exactly ONE of the following THREE questions: Maximum Marks: 25
(a) Disjoint Set Union. Describe the amortized analysis of the DSU data structure, using the
properties of rank and groups as a black box (without explicit proof).
Grading Policy. Not explicit, marks are deducted based on mistakes or incompleteness.
(b) Fast Fourier Transform. Describe and analyze the divide and conquer algorithm to compute
FFT using properties of roots of unity as a black box (without explicit proof).
Grading Policy. Not explicit, marks are deducted based on mistakes or incompleteness.
(c) String Matching using FFT. Given a text T and a pattern P , describe and analyze an algo-
rithm to compute the number of occurrences of P in T using Fast Fourier Transform. Also, prove
the correctness of the algorithm explicitly.
Grading Policy. Marks Distribution:
i. [10 Marks] Polynomial Definition,
ii. [10 Marks] Proof for matched,
iii. [5 Marks] Analysis.
4. Answer exactly ONE of the following TWO questions: Maximum Marks: 20
2
(Aa) Maximum Difference in an array. Given an array A of n positive integers, the difference
of the ordered pair (i, j) where i ≤ j is A[j] − A[i]. Design and analyze a divide and conquer
algorithm to compute the pair having the maximum difference.
Solution. Following subproblems:
M axD[a, b] = Maximum difference for a ≤ i ≤ j ≤ b.
max[a, b] = Maximum element in A[a], · · · , A[b]
min[a, b] = Minimum element in A[a], · · · , A[b]
Divide step: Compute for first half and second half recursively.
Combine step: Base case 0 added for case of decreasing array, either by going till a = b or 0.
M axD[a, b] = max(M axD[a, a+b a+b a+b a+b
2 ], M axD[ 2 + 1, b], max[ 2 + 1, b] − min[[a, 2 ]], 0)
max[a, b] = max(max[a, a+b a+b
2 ], max[ 2 + 1, b])
a+b a+b
min[a, b] = max(min[a, 2 ], min[ 2 + 1, b])
Grading Policy.
i. Distribution: [15 Marks] Algorithm (define variables 5 Marks), [5 Marks] Analysis.
ii. Deduc t 90% if non-divide and conquer algorithm presented.
iii. Deduct 70% if complexity ω(n).
iv. Deduct 10% if decreasing array not handled.
(Ab) Rank in two sorted arrays. Given two sorted Arrays of size m and n. Design and analyze an
algorithm to compute the k th smallest number in the union of two arrays.
Solution. Clearly if m > k or n > k we can ignore the elements after k, so effectively m, n ≤ k.
Various variants of solutions described in have O(log k) complexity assuming the above fact.
https://www.geeksforgeeks.org/k-th-element-two-sorted-arrays/
Grading Policy.
i. Distribution: [15 Marks] Algorithm, [5 Marks] Analysis.
ii. Deduct 60% if complexity is Θ(log2 k) or Θ(log m log n) etc.
iii. Deduct 80% if complexity is ω(log2 k) or ω(log m log n)/
iv. Deduct 1 Mark if space not analyzed.
(Ba) Maximum Sum Subarray. Given an array A of n integers, the sum of its sub-array is A[i, j] =
A[i] + A[i + 1] + ... + A[j]. Design and analyze a divide and conquer algorithm to compute the
subarray having the maximum sum.
Solution. Following subproblems:
M axSm[a, b] = Maximum sum A[i, j] for a ≤ i ≤ j ≤ b.
maxP x[a, b] = Maximum sum of a prefix A[a, i] for a ≤ i ≤ b
maxSx[a, b] = Maximum sum of a suffix A[i, b] for a ≤ i ≤ b
totalSm[a, b] = Total sum of array A[a, b].
Divide step: Compute for first half and second half recursively.
Combine step: Base case minimum for case of negative array, by going till a = b.
M axSm[a, b] = max(M axSm[a, a+b a+b a+b a+b
2 ], M axSm[ 2 + 1, b], maxP x[ 2 + 1, b] + maxSx[[a, 2 ]])
a+b a+b a+b
maxP x[a, b] = max(maxP x[a, 2 ], totalSm[a, 2 ] + maxP x[ 2 + 1, b])
maxSx[a, b] = max(maxSx[a, a+b a+b a+b
2 ] + totalSm[ 2 + 1, b], maxSx[ 2 + 1, b])
a+b a+b
totalSm[a, b] = totalSm[a, 2 ] + totalSm[ 2 + 1, b]
Grading Policy.
i. Distribution: [15 Marks] Algorithm, [5 Marks] Analysis.
ii. Deduc t 90% if non-divide and conquer algorithm presented.
iii. Deduct 70% if complexity ω(n).
iv. Deduct 10% if negative array not handled.
3
(Bb) k-way merge. Suppose you have k sorted arrays, each with n elements. Design and analyze an
algorithm to combine them into a single sorted array of kn elements.
Solution. Merge k arrays similar to merge sort (assume starting from log n the level such that
each recursively solved subproblem already has n elements). This can be done in O(log k) levels,
each level merging nk elements with each other. Time complexity is O(nk log k), space complexity
is O(nk).
Grading Policy.
i. Distribution: [15 Marks] Algorithm, [5 Marks] Analysis.
ii. Deduct 80% if complexity ω(nk log k).
iii. Deduct 1 Mark if space not analyzed.
4
i. [15 Marks] Describe the polynomial formulation.
ii. [10 Marks] Describe and prove the procedure for computation of results using FFT.
iii. [5 Marks] Complexity Analysis. Time complexity in terms of input.
iv. Deduct 90% for ω(log n) solution.
v. Deduct 20-100% in the corresponding part based on the severity of the mistake.
(Ba) Random Walk. Facing the extreme exam stress, the students of IIT Roorkee are found sleep-
walking at 2 am. They can take steps in any direction but are still aware enough to avoid short
circles and short-term repetitions. We need to compute the number of possible paths taken using
n steps starting from the library. Essentially, compute all possible strings of {L, R, D, U } such
that circles (or U RDL, DLU R, U LDR, RDLU , etc.) are avoided where as U DLR or RLDU are
allowed. Further, immediate and alternate characters should not be the same, or ith character
cannot be the same as i + 1th or i + 2th character. Design and analyze an algorithm to compute
number of such strings of length n.
Solution. https://discuss.codechef.com/t/cr195-editorial/22145
Grading Policy.
i. [15 Marks] DP Formulation. Clearly define the variable used [5 Marks]
ii. [10 Marks] Matrix Formulation. Describe the base case and size of the matrix [5 Marks].
iii. [5 Marks] Complexity Analysis. Time complexity in terms of input.
iv. Deduct 90% for ω(log n) solution.
v. Deduct 20-100% in the corresponding part based on the severity of the mistake.
(Bb) Smallest Triangle. Given a set of n points on a 2D plane, design and analyze an algorithm to
find three points making a triangle of the smallest size (perimeter).
Solution. Application of closest pair of points. Only difference is proof for existence of constant
triangles from a vertex.
Grading Policy.
i. [15 Marks] Algorithm,
ii. [10 Marks] Proof of comparison with Constant vertices.
iii. [5 Marks] Analysis.
iv. Deduct 90% marks if ω(n log2 n) algorithm given and 60% if Θ(n log2 n) given. solution.
v. Deduct 20-100% in the corresponding part based on the severity of the mistake.