GATE 2006
191 questions
MCQ 1911-mark 191
Questions 46–50 of 191
A set X can be represented by an array x[n] as follows
Consider the following algorithm in which x,y and z are boolean arrays of size n;
Consider the following algorithm in which x,y and z are boolean arrays of size n;
algorithm zzz(x[] , y[], z [])
{
int i;
for (i=O; i < n; ++i)
z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i])
}
The set Z computed by the algorithm isAnswer: (D)
Correct Option: D
The for loop in the algorithm has a logical expression:
z[i] = (x[i] ∧ ~y[i]) ∨ (~x[i] ∧ y[i]);
Now write this expression in set form. Let us take . Then:
Let T be a depth first search tree in a undirected graph G Vertices u and v are leaves of this tree T. The degrees of both u and v in G are at least 2. Which one of the following statements is true?
Answer: (D)
In a DFS tree of an undirected graph, every edge of G that is not a tree edge joins a vertex to one of its ancestors (there are no cross edges).
Let u be a leaf. It has no descendants, so every neighbour of u is an ancestor of u, that is, it lies on the path from the root down to u. In the figure, u = U is a leaf and its neighbours K and L are both ancestors of U.
The parent of u is one neighbour. Since u has degree at least 2, it has another neighbour, and that one is higher up the path than the parent. Let w be the highest neighbour of u on the path. The tree path from w down to u, together with the edge (u, w), is a cycle. Every neighbour of u lies on that tree path, so the cycle contains u and all its neighbours. So (D) always holds.
Why the others can fail:
Example 1: vertices r, a, b, u, x, v. Edges r–a, a–b, b–u, b–x, x–v, u–r, v–a. This is a valid DFS tree from r with tree edges r–a, a–b, b–u, b–x, x–v, because both extra edges (u–r and v–a) join a vertex to its ancestor. The leaves u and v both have degree 2.
(A) is false here: the neighbours of u are {b, r} and the neighbours of v are {x, a}, so no vertex is adjacent to both.
(B) is false here: removing any single vertex other than u or v leaves u and v connected (for example, removing b leaves the path u–r–a–v).
(C) Example 2: two triangles r–a–u and r–c–v sharing only r. DFS from r gives leaves u and v. A cycle through u must stay inside the first triangle and a cycle through v inside the second, so no cycle contains both.
Answer: (D)
Let u be a leaf. It has no descendants, so every neighbour of u is an ancestor of u, that is, it lies on the path from the root down to u. In the figure, u = U is a leaf and its neighbours K and L are both ancestors of U.
The parent of u is one neighbour. Since u has degree at least 2, it has another neighbour, and that one is higher up the path than the parent. Let w be the highest neighbour of u on the path. The tree path from w down to u, together with the edge (u, w), is a cycle. Every neighbour of u lies on that tree path, so the cycle contains u and all its neighbours. So (D) always holds.
Why the others can fail:
Example 1: vertices r, a, b, u, x, v. Edges r–a, a–b, b–u, b–x, x–v, u–r, v–a. This is a valid DFS tree from r with tree edges r–a, a–b, b–u, b–x, x–v, because both extra edges (u–r and v–a) join a vertex to its ancestor. The leaves u and v both have degree 2.
(A) is false here: the neighbours of u are {b, r} and the neighbours of v are {x, a}, so no vertex is adjacent to both.
(B) is false here: removing any single vertex other than u or v leaves u and v connected (for example, removing b leaves the path u–r–a–v).
(C) Example 2: two triangles r–a–u and r–c–v sharing only r. DFS from r gives leaves u and v. A cycle through u must stay inside the first triangle and a cycle through v inside the second, so no cycle contains both.
Answer: (D)
Let SHAM3 be the problem of finding a Hamiltonian cycle in a graph G=(V,E) with |V| divisible by 3 and DHAM3 be the problem of determining if a Hamltonian cycle exists in such graphs. Which one of the following is true?
Answer: (A)
Both problems are about graphs whose number of vertices is a multiple of 3. DHAM3 asks yes or no (does a Hamiltonian cycle exist); SHAM3 asks for the cycle itself.
DHAM3 is NP-hard. Reduce general Hamiltonian cycle to it. Given a graph G with n vertices, if n is not a multiple of 3, pick a vertex v and replace it by a path v1–v2–v3, where v1 and v3 are each joined to all neighbours of v (v2 is joined only to v1 and v3). Any Hamiltonian cycle through v becomes one through v1, v2, v3 in order, and any Hamiltonian cycle in the new graph must pass through v1, v2, v3 in a row and so gives one in G. This adds 2 vertices and keeps the answer. Doing it for at most 2 different vertices makes the vertex count a multiple of 3. Since general Hamiltonian cycle is NP-complete, DHAM3 is NP-hard.
SHAM3 is NP-hard. An algorithm that finds the cycle also decides whether one exists (it either returns a cycle or reports none). So SHAM3 is at least as hard as DHAM3.
So both are NP-hard.
Answer: (A)
DHAM3 is NP-hard. Reduce general Hamiltonian cycle to it. Given a graph G with n vertices, if n is not a multiple of 3, pick a vertex v and replace it by a path v1–v2–v3, where v1 and v3 are each joined to all neighbours of v (v2 is joined only to v1 and v3). Any Hamiltonian cycle through v becomes one through v1, v2, v3 in order, and any Hamiltonian cycle in the new graph must pass through v1, v2, v3 in a row and so gives one in G. This adds 2 vertices and keeps the answer. Doing it for at most 2 different vertices makes the vertex count a multiple of 3. Since general Hamiltonian cycle is NP-complete, DHAM3 is NP-hard.
SHAM3 is NP-hard. An algorithm that finds the cycle also decides whether one exists (it either returns a cycle or reports none). So SHAM3 is at least as hard as DHAM3.
So both are NP-hard.
Answer: (A)
Consider the following propositional statements:
Which one of the following is true?
Which one of the following is true?
Answer: (D)
(D) Neither nor is a tautology.
For take true, false and C false. Then the LHS of is true, but the RHS becomes false. So it is not a tautology.
For the forward side is true, but the reverse side is not true. Take false, true and C false. Then the RHS is true, but the LHS is false.
The LHS of can be simplified in these steps:
For take true, false and C false. Then the LHS of is true, but the RHS becomes false. So it is not a tautology.
For the forward side is true, but the reverse side is not true. Take false, true and C false. Then the RHS is true, but the LHS is false.
The LHS of can be simplified in these steps:
Which one of the first order predicate calculus statements given below correctly expresses the following English statement?
Tigers and lions attack if they are hungry or threatened.
Tigers and lions attack if they are hungry or threatened.
Answer: (D)
"Tigers and lions attack if they are hungry or threatened" means: for every animal , if is a tiger or a lion, then (if is hungry or threatened, then attacks):
This is option (D). The other options fail:
- (A) uses , which talks only about an animal that is both a tiger and a lion. The "and" in "tigers and lions" means each of them, so it is "or" in the condition.
- (B) has as the result. That says every tiger or lion is hungry or threatened and attacks, all the time.
- (C) has . This reverses the implication, and it needs both hungry and threatened.