Graph Theory · Discrete Mathematics
86 questions · asked in 25 of 27 years (2000–2026)
MCQ 59 · MSQ 9 · NAT 181-mark 55 · 2-mark 31
Questions 66–70 of 86
Answer: (A)
DHAM3 is NP-hard. Hamiltonian cycle is NP-complete for general graphs. Given any graph G with n vertices, replace one vertex v by three vertices: and joined to all neighbours of v, and a middle vertex joined only to and . Because has degree 2, any Hamiltonian cycle must go , which acts exactly like passing through v. So the new graph has a Hamiltonian cycle if and only if G has one, and it has 2 more vertices. Doing this 0, 1 or 2 times makes the number of vertices a multiple of 3. This is a polynomial-time reduction, so DHAM3 is NP-hard.
SHAM3 is NP-hard. If we could find a Hamiltonian cycle in polynomial time, we could decide existence too: answer yes when a cycle is returned and no otherwise. So finding is at least as hard as deciding, and SHAM3 is NP-hard as well.
So both are NP-hard.
Answer: (A)
i = 0;
do {
j = i + 1;
while ((j < n) && E1) j++;
if (j < n) E2;
} while (j < n);
flag = 1;
for (j = 0; j < n; j++)
if ((j != i) && E3) flag = 0;
if (flag) printf("Sink exists") ;
else printf ("Sink does not exist"); Choose the correct expression for .
Answer: (D)
If the graph has a sink, the adjacency matrix has all 1s (except the diagonal) in one column, and all 0s (except the diagonal) in the row of that same vertex. The given algorithm is a smart way to check this, as it finds the only possible sink in time.
The first part of the code finds a vertex that has no outgoing edge to any vertex after it in the adjacency matrix. The smart part of the code is . It skips rows when there is no edge from i to them, because such rows can never form a sink. This is done through
and
;
makes sure that there is no edge from to , and stays a potential sink till becomes . If becomes , then can no longer be a sink. In the same way, all earlier can also not be a sink, since there was no edge from to them and a sink needs an edge from all other vertices. Now the next potential candidate for the sink is . So, in , we must make .
When the loop ends, is the only vertex that can be a sink. The last loop checks every . Vertex is a sink only if (no edge from to ) and (an edge from to ).
The code starts with (sink exists). So must be true when either condition fails for some : (i has an outgoing edge) or (an incoming edge is missing). So
The other options fail:
(A) is true only when both conditions fail, so it misses a vertex where only one fails.
(B) is true exactly when fits a sink, so it would clear the flag for a real sink.
(C) is also true when fits a sink, so it would clear the flag for a real sink too.
Answer: (D)
i = 0;
do {
j = i + 1;
while ((j < n) && E1) j++;
if (j < n) E2;
} while (j < n);
flag = 1;
for (j = 0; j < n; j++)
if ((j != i) && E3) flag = 0;
if (flag) printf("Sink exists") ;
else printf ("Sink does not exist"); Choose the correct expressions for and .
Answer: (C)
If the graph has a sink, its column in the adjacency matrix is all 1's (except the diagonal) and its row is all 0's (except the diagonal). The algorithm finds the only possible sink in time. The options give and , so these are the two expressions to find.
The loop keeps a candidate and scans . It must go on while there is no edge from to , and stop at the first with an edge. So . stays a possible sink while .
When the loop stops at , cannot be a sink, because a sink has no outgoing edge. Every vertex between and cannot be a sink either, because there was no edge from to it and a sink needs an edge from every other vertex. The next possible sink is , so .
The other options fail. (A) and (D) use , which skips while there is an edge, the wrong way round. (B) and (D) use , which skips even though it just received an edge from and may be the sink.
The final loop then checks the candidate. is : if has an edge to , or has no edge to , then is not a sink and the flag becomes 0.
Answer: (C)
Answer: (D)
Tree edges are the edges that end up in the final DFS forest. Take a connected graph, where the DFS forest is just one tree. If we run DFS on it, the edges of that DFS tree are the tree edges.
Say the graph has connected components (strongly connected components if the graph is directed). The 1st component has tree edges, the 2nd has tree edges, and the xth has tree edges.
So the total is:
We can also see it this way. The final DFS forest has trees. These trees have , , edges respectively.
A tree with edges has nodes. In the same way, a tree with edges has nodes, and so on.
So the sum of the nodes in all the trees
Correct Answer:
Answer: (A)
If is a vertex cover, then no edge has both ends outside . So the vertices outside are an independent set. In the other direction, if is an independent set, every edge has at most one end in , so at least one end outside . So the vertices outside are a vertex cover.
So is a vertex cover exactly when is an independent set. The smallest vertex cover gives the largest independent set:
Size of maximum independent set size of minimum vertex cover .
Answer: (A)
Keep practising