uiz Space

May 2025 term · Advanced Algorithms · BSCS4021

Advanced Algorithms End Term: 31 August 2025, Set QIA1 (May 2025 term)

The IIT Madras BS Advanced Algorithms (Advanced Algorithms) End Term paper sat on 31 Aug 2025, in the May 2025 term, set QIA1: 21 questions for 50 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
21
Marks
50
Duration
180 min
MCQ
17
Numerical
2
MSQ
2

Updated

Official paper: IIT M IMPROVEMENT FN EXAM QIA1 31 Aug 2025 · No negative marking.

Question 1

+3 marksOne correct option

In this problem you are given as input a graph T=(V,E)T = (V, E) that is a tree (that is, TT is undirected, connected, and acyclic). A perfect matching of TT is a subset F⊂EF \subset E of edges such that every vertex v∈Vv \in V is the endpoint of exactly one edge of FF.

Equivalently, FF matches each vertex of TT with exactly one other vertex of TT. For example, a path graph has a perfect matching if and only if it has an even number of vertices.

Consider the following two algorithms that attempt to decide whether or not a given tree has a perfect matching. The degree of a vertex in a graph is the number of edges incident to it.

Algorithm A:

text
1 While T has at least one vertex:
2 If T has no edges:
3 halt and output ”T has no perfect matching.”
4 Else:
5 Let v be a vertex of T with maximum degree.
6 Choose an arbitrary edge e incident to v.
7 Delete e and its two endpoints from T.
8 (end of while loop]
9 Halt and output ”T has a perfect matching.”

Algorithm B:

text
1 While T has at least one vertex:
2 If T has no edges:
3 halt and output ”T has no perfect matching.”
4 Else:
5 Let v be a vertex of T with minimum non-zero degree.
6 Choose an arbitrary edge e incident to v.
7 Delete e and its two endpoints from T.
8 (end of while loop]
9 Halt and output ”T has a perfect matching.”

Is either algorithm correct?

Hint: Recall that every tree with at least two vertices has at least one degree one vertex.

  1. A

    Neither algorithm always correctly determines whether or not a given tree graph has a perfect matching.

  2. B

    Both algorithms always correctly determine whether or not a given tree graph has a perfect matching.

  3. C

    Algorithm B always correctly determines whether or not a given tree graph has a perfect matching; algorithm A does not.

  4. D

    Algorithm A always correctly determines whether or not a given tree graph has a perfect matching; algorithm B does not.

Show answer

Correct answer

  • C

    Algorithm B always correctly determines whether or not a given tree graph has a perfect matching; algorithm A does not.

Question 2

+2 marksOne correct option

Consider the task of counting how many sequences of length nn exist consisting only of numbers 00, 11, and 22 such that each number occurs at least once. We will solve this by calculating the number of sequences which do not contain at least one of the numbers.

Let's denote by AiA_i (i=0,1,2)(i = 0, 1, 2) the set of sequences in which the digit ii does not occur. The formula of inclusion-exclusion on the number of "bad" sequences is given by:

∣A0∪A1∪A2∣=∣A0∣+∣A1∣+∣A2∣−∣A0∩A1∣−∣A0∩A2∣−∣A1∩A2∣+∣A0∩A1∩A2∣|A_0 \cup A_1 \cup A_2| = |A_0| + |A_1| + |A_2| - |A_0 \cap A_1| - |A_0 \cap A_2| - |A_1 \cap A_2| + |A_0 \cap A_1 \cap A_2|

Based on the above data, answer the given subquestions.

  1. A

    3ⁿ

  2. B

    2ⁿ

  3. C

    n³

  4. D

    n²

Show answer

Correct answer

  • B

    2ⁿ

Question 3

+2 marksOne correct option

Consider the task of counting how many sequences of length nn exist consisting only of numbers 00, 11, and 22 such that each number occurs at least once. We will solve this by calculating the number of sequences which do not contain at least one of the numbers.

Let's denote by AiA_i (i=0,1,2)(i = 0, 1, 2) the set of sequences in which the digit ii does not occur. The formula of inclusion-exclusion on the number of "bad" sequences is given by:

∣A0∪A1∪A2∣=∣A0∣+∣A1∣+∣A2∣−∣A0∩A1∣−∣A0∩A2∣−∣A1∩A2∣+∣A0∩A1∩A2∣|A_0 \cup A_1 \cup A_2| = |A_0| + |A_1| + |A_2| - |A_0 \cap A_1| - |A_0 \cap A_2| - |A_1 \cap A_2| + |A_0 \cap A_1 \cap A_2|

Based on the above data, answer the given subquestions.

  1. A

    2ⁿ

  2. B

    n

  3. C

    1

  4. D

    0

Show answer

Correct answer

  • C

    1

Question 4

+2 marksOne correct option

Consider the task of counting how many sequences of length nn exist consisting only of numbers 00, 11, and 22 such that each number occurs at least once. We will solve this by calculating the number of sequences which do not contain at least one of the numbers.

Let's denote by AiA_i (i=0,1,2)(i = 0, 1, 2) the set of sequences in which the digit ii does not occur. The formula of inclusion-exclusion on the number of "bad" sequences is given by:

∣A0∪A1∪A2∣=∣A0∣+∣A1∣+∣A2∣−∣A0∩A1∣−∣A0∩A2∣−∣A1∩A2∣+∣A0∩A1∩A2∣|A_0 \cup A_1 \cup A_2| = |A_0| + |A_1| + |A_2| - |A_0 \cap A_1| - |A_0 \cap A_2| - |A_1 \cap A_2| + |A_0 \cap A_1 \cap A_2|

Based on the above data, answer the given subquestions.

  1. A

    3ⁿ

  2. B

    2ⁿ

  3. C

    1

  4. D

    0

Show answer

Correct answer

  • D

    0

Question 5

+2 marksNumerical answer

Consider the task of counting how many sequences of length nn exist consisting only of numbers 00, 11, and 22 such that each number occurs at least once. We will solve this by calculating the number of sequences which do not contain at least one of the numbers.

Let's denote by AiA_i (i=0,1,2)(i = 0, 1, 2) the set of sequences in which the digit ii does not occur. The formula of inclusion-exclusion on the number of "bad" sequences is given by:

∣A0∪A1∪A2∣=∣A0∣+∣A1∣+∣A2∣−∣A0∩A1∣−∣A0∩A2∣−∣A1∩A2∣+∣A0∩A1∩A2∣|A_0 \cup A_1 \cup A_2| = |A_0| + |A_1| + |A_2| - |A_0 \cap A_1| - |A_0 \cap A_2| - |A_1 \cap A_2| + |A_0 \cap A_1 \cap A_2|

Based on the above data, answer the given subquestions.

For n = 4, calculate the number of sequences of length 4 consisting only of numbers 0, 1, and 2 such that each number occurs at least once.

Show answer

Correct answer: 36

Question 6

+2 marksNumerical answer

Consider the task of counting how many sequences of length nn exist consisting only of numbers 00, 11, and 22 such that each number occurs at least once. We will solve this by calculating the number of sequences which do not contain at least one of the numbers.

Let's denote by AiA_i (i=0,1,2)(i = 0, 1, 2) the set of sequences in which the digit ii does not occur. The formula of inclusion-exclusion on the number of "bad" sequences is given by:

∣A0∪A1∪A2∣=∣A0∣+∣A1∣+∣A2∣−∣A0∩A1∣−∣A0∩A2∣−∣A1∩A2∣+∣A0∩A1∩A2∣|A_0 \cup A_1 \cup A_2| = |A_0| + |A_1| + |A_2| - |A_0 \cap A_1| - |A_0 \cap A_2| - |A_1 \cap A_2| + |A_0 \cap A_1 \cap A_2|

Based on the above data, answer the given subquestions.

For n = 5, calculate the number of sequences of length 5 consisting only of numbers 0, 1, and 2 such that each number occurs at least once.

Show answer

Correct answer: 150

Question 7

+3 marksOne or more correct options

Select all that apply.

  1. A

    It is in P.

  2. B

    It is in NP.

  3. C

    It is NP-hard.

  4. D

    It is NP-complete.

Show answer

Correct answers

  • A

    It is in P.

  • B

    It is in NP.

Question 8

+3 marksOne or more correct options

Choose the correct options:

Select all that apply.

  1. A
  2. B
  3. C
Show answer

Correct answers

  • A
  • C

Question 9

+2 marksOne correct option
  1. A

    TRUE

  2. B

    FALSE

Show answer

Correct answer

  • A

    TRUE

Question 10

+3 marksOne correct option

Consider the following instance of Set Cover problem:

  • Universe U={a,b,c}\mathcal{U} = \{a, b, c\}
  • Family F={S1={a,b},S2={a},S3={b},S4={c}}\mathcal{F} = \{S_1 = \{a, b\}, S_2 = \{a\}, S_3 = \{b\}, S_4 = \{c\}\}

We build the following DP table for finding the Minimum Set Cover.

Π(X,j)\Pi(X, j) : minimum number of sets from S1,…,SjS_1, \ldots, S_j required to cover XX

jj / XXϕ\phi{a}\{a\}{b}\{b\}{c}\{c\}{a,b}\{a, b\}{a,c}\{a, c\}{b,c}\{b, c\}{a,b,c}\{a, b, c\}
00∞\infty∞\infty∞\infty∞\infty∞\infty∞\infty∞\infty
1011∞\infty1∞\infty∞\infty∞\infty
2011∞\infty1∞\infty∞\infty∞\infty
3011∞\infty1∞\infty∞\infty∞\infty
40111122?

What is the missing entry?

  1. A

    0

  2. B

    1

  3. C

    2

  4. D

    3

Show answer

Correct answer

  • C

    2

Question 11

+3 marksOne correct option

Consider the following instance of Set Cover problem:

  • Universe U={a,b,c,d}\mathcal{U} = \{a, b, c, d\}
  • Family F={S1={a,c},S2={a,d},S3={b,d},S4={b,c}}\mathcal{F} = \left\{S_1 = \{a, c\}, S_2 = \{a, d\}, S_3 = \{b, d\}, S_4 = \{b, c\}\right\}

We use dynamic programming to find the minimum number of sets from F\mathcal{F} required to cover U\mathcal{U}. Recall that for every X⊆UX \subseteq \mathcal{U} and every 0≤j≤∣F∣0 \leq j \leq |\mathcal{F}|, our algorithm computes and stores Π(X,j)\Pi(X, j), i.e., minimum number of sets from Fj={S1,…,Sj}\mathcal{F}_j = \{S_1, \ldots, S_j\} required to cover XX.

Consider the following DP table:

{a,b,c,d}\{a, b, c, d\}∞\infty∞\infty∞\infty22
{b,c,d}\{b, c, d\}∞\infty∞\infty∞\infty22
{a,c,d}\{a, c, d\}∞\infty∞\infty222
{a,b,d}\{a, b, d\}∞\infty∞\infty∞\infty22
{a,b,c}\{a, b, c\}∞\infty∞\infty∞\infty22
{c,d}\{c, d\}∞\infty∞\infty222
{b,d}\{b, d\}∞\infty∞\infty∞\infty11
{b,c}\{b, c\}∞\infty∞\infty∞\infty21
{a,d}\{a, d\}∞\infty∞\infty111
{a,c}\{a, c\}∞\infty1111
{a,b}\{a, b\}∞\infty∞\infty∞\infty22
{d}\{d\}∞\infty∞\infty111
{c}\{c\}∞\infty1111
{b}\{b\}∞\infty∞\infty∞\infty11
{a}\{a\}∞\infty1111
Φ\Phi00000
XX / jj01234

Based on the above data, answer the given subquestions.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 12

+3 marksOne correct option

Consider the following instance of Set Cover problem:

  • Universe U={a,b,c,d}\mathcal{U} = \{a, b, c, d\}
  • Family F={S1={a,c},S2={a,d},S3={b,d},S4={b,c}}\mathcal{F} = \left\{S_1 = \{a, c\}, S_2 = \{a, d\}, S_3 = \{b, d\}, S_4 = \{b, c\}\right\}

We use dynamic programming to find the minimum number of sets from F\mathcal{F} required to cover U\mathcal{U}. Recall that for every X⊆UX \subseteq \mathcal{U} and every 0≤j≤∣F∣0 \leq j \leq |\mathcal{F}|, our algorithm computes and stores Π(X,j)\Pi(X, j), i.e., minimum number of sets from Fj={S1,…,Sj}\mathcal{F}_j = \{S_1, \ldots, S_j\} required to cover XX.

Consider the following DP table:

{a,b,c,d}\{a, b, c, d\}∞\infty∞\infty∞\infty22
{b,c,d}\{b, c, d\}∞\infty∞\infty∞\infty22
{a,c,d}\{a, c, d\}∞\infty∞\infty222
{a,b,d}\{a, b, d\}∞\infty∞\infty∞\infty22
{a,b,c}\{a, b, c\}∞\infty∞\infty∞\infty22
{c,d}\{c, d\}∞\infty∞\infty222
{b,d}\{b, d\}∞\infty∞\infty∞\infty11
{b,c}\{b, c\}∞\infty∞\infty∞\infty21
{a,d}\{a, d\}∞\infty∞\infty111
{a,c}\{a, c\}∞\infty1111
{a,b}\{a, b\}∞\infty∞\infty∞\infty22
{d}\{d\}∞\infty∞\infty111
{c}\{c\}∞\infty1111
{b}\{b\}∞\infty∞\infty∞\infty11
{a}\{a\}∞\infty1111
Φ\Phi00000
XX / jj01234

Based on the above data, answer the given subquestions.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 13

+3 marksOne correct option

In the MIN-2-SAT problem, we are given a 2-CNF formula ϕ\phi and an integer kk, and the objective is to decide whether there exists an assignment for ϕ\phi that satisfies at most kk clauses.

Consider the following branching algorithm for the problem.

If there is a variable xx that occurs only positively in ϕ\phi, observe that there exists an optimal assignment that sets it to 0. Similarly, if there is a variable xx that occurs only positively in ϕ\phi, there exists an optimal assignment that sets it to 1. Once we perform this preprocessing, assuming that have clauses remaining, we have the following guarantee:

Every variable has at least one positive and one negated occurrence.

Now we can branch exhuastively on the settings of variables. The overall algorithm is summarized in the following pseudocode:

text
MINSAT(phi,k):
if there is a variable x that occurs only as a positive literal:
set x to 0
if there is a variable x that occurs only as a negated literal:
set x to 1
if phi is empty:
return YES
if phi is not empty and k <= 0:
return NO
Let x be any variable that occurs in phi.
return MINSAT(phi|[x = TRUE],k-1) OR MINSAT(phi|[x = FALSE],k-1)

What is the running time of this algorithm? Select the tightest bound that is correct according to you.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 14

+2 marksOne correct option

Consider the following statements and answer the given subquestions if they are true or false.

The worst-case running time and expected running time are equal to within constant factors for any randomized algorithm.

  1. A

    TRUE

  2. B

    FALSE

Show answer

Correct answer

  • B

    FALSE

Question 15

+2 marksOne correct option

Consider the following statements and answer the given subquestions if they are true or false.

An adversary can provide randomized quicksort with an input array of length nn that forces the algorithm to run in ω(nlg⁡n)\omega(n \lg n) time on that input.

(If you are not familiar with the ω\omega asymptotic notation, it roughly translates as “at least’ ’. For example, we can say that it is possible to come up with an input that forces insertion sort to run for ω(n2)\omega(n^2) steps.)

  1. A

    TRUE

  2. B

    FALSE

Show answer

Correct answer

  • B

    FALSE

Question 16

+2 marksOne correct option

Answer the given subquestions.

Every linear program has a unique optimal solution.

  1. A

    TRUE

  2. B

    FALSE

Show answer

Correct answer

  • B

    FALSE

Question 17

+2 marksOne correct option

Answer the given subquestions.

Recall that in the vertex cover problem,we are trying to find a smallest subset SS of vertices in a graph GG such that G∖SG \setminus S is an independent set; in other words, for every edges (u,v)(u, v) in the graph GG, we have that {u,v}∩S\{u, v\} \cap S is non-empty.

Consider the algorithm that repeats the following steps as long as the graph has at least one edge available: select a vertex of maximum degree (say ww), and include ww in the solution; thereafter, delete ww and all edges incident to ww.

Is it true that the algorithm always outputs a vertex cover?

  1. A

    Yes

  2. B

    No

Show answer

Correct answer

  • A

    Yes

Question 18

+2 marksOne correct option

Answer the given subquestions.

Consider the algorithm in the previous question no 18. Does the algorithm always output an optimal vertex cover?

  1. A

    Yes

  2. B

    No

Show answer

Correct answer

  • B

    No

Question 19

+2 marksOne correct option

Answer the given subquestions.

Consider the algorithm in the previous question no 18. Does the algorithm always output a 2- approximate vertex cover?

  1. A

    Yes

  2. B

    No

Show answer

Correct answer

  • B

    No

Question 20

+2 marksOne correct option

Answer the given subquestions.

Recall that the size of an optimal vertex cover is at most twice the size of a maximum matching of a graph G. Are there examples of graphs where the size of the optimal vertex cover is exactly equal to twice the size of its maximum matching? For example, this is not true for a path on three vertices: the size of both the maximum matching and minimum vertex cover is 1.

  1. A

    Yes

  2. B

    No

Show answer

Correct answer

  • A

    Yes

Question 21

+3 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D