0% found this document useful (0 votes)
15 views9 pages

Pgcs

The document is an entrance examination paper for the M.Sc. / Ph.D. Programme in Computer Science at Chennai Mathematical Institute, held on May 18, 2017. It consists of two parts: Part A with 10 questions worth 3 marks each and Part B with 7 questions worth 10 marks each, covering topics such as regular expressions, probability, logic, graph theory, and algorithms. Each question includes a solution and explanation for the correct answer.

Uploaded by

jainaarushi434
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)
15 views9 pages

Pgcs

The document is an entrance examination paper for the M.Sc. / Ph.D. Programme in Computer Science at Chennai Mathematical Institute, held on May 18, 2017. It consists of two parts: Part A with 10 questions worth 3 marks each and Part B with 7 questions worth 10 marks each, covering topics such as regular expressions, probability, logic, graph theory, and algorithms. Each question includes a solution and explanation for the correct answer.

Uploaded by

jainaarushi434
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/ 9

CHENNAI MATHEMATICAL INSTITUTE

M.Sc. / Ph.D. Programme in Computer Science


Entrance Examination, 18 May 2017
(With solutions)

This question paper has 5 printed sides. Part A has 10 questions of 3 marks each. Part B has
7 questions of 10 marks each. The total marks are 100. Answers to Part A must be filled in
the answer sheet provided.

Part A
1. The regular expression (a∗ + b)∗ is equivalent to which of the following regular expres-
sions:
(a) a∗ b∗ (b) (a∗ b + b)∗ (c) (a + b∗ )∗ (d) (a∗ b)∗

Answer: (c) (a + b∗ )∗

(a∗ + b)∗ allows any string over {a, b} and is the same as (a + b)∗ . Option (a) only
allows strings of the form ai bj . Options (b) and (d) do not allow strings of the form
ai with no b’s. a

2. An FM radio channel has a repository of 10 songs. Each day, the channel plays 3
distinct songs that are chosen randomly from the repository.
Mary decides to tune in to the radio channel on the weekend after her exams. What
is the probability that no song gets repeated during these 2 days?
10 2 10 −1
 
(a) 3
· 6
10 10 −2
 
(b) 6
· 3
10 7 10 −2
  
(c) 3
· 3
· 3
10 7 10 −1
  
(d) 3
· 3
· 6

10 7 10 −2
  
Answer: (c ) 3
· 3
· 3

10 7
 
3
is the number of ways of choosing 3 songs on day 1. 3
is the number of ways
10 7
 
of choosing 3 different songs on day 2, so 3 3
is the number of combinations that
10 10
 
meet Mary’s requirement. 3 3 is the total number of ways of choosing 3 songs on
each of the two days, without any constraints. The ratio is the given probability. a

3. Four siblings go shopping with their father. If Abhay gets shoes, then Asha does not
get a necklace. If Arun gets a T-shirt, then Aditi gets bangles. If Abhay does not get
shoes or Aditi gets bangles, the mother will be happy. Which of the following is true?

(a) If the mother is happy, then Aditi got bangles.

1
(b) If Aditi got bangles, then Abhay got shoes.
(c) If the mother is not happy, then Asha did not get a necklace and Arun did not
get a T-shirt.
(d) None of the above.

Answer: (c ) If the mother is not happy, then Asha did not get a necklace and
Arun did not get a T-shirt.

Let p denote that Asha get a necklace, q denote that Abhay gets shoes, r denote that
Arun gets a T-shirt, s denote that Aditi gets bangles and w denote that mother is
happy. The question is equivalent to the formula φ : q → ¬p ∧ r → s ∧ (¬q ∨ s) → w.
A formula ψ is a valid implication iff every truth assignment to p, q, r, s, w that makes
φ true also makes ψ true. Option (a) is the formula ψa : w → s, option (b) is the
formula ψb : s → q and option (c) is the formula ψc : ¬w → (¬p ∧ ¬r). Neither ψa nor
ψb are valid implications but ψc is.
a

4. City authorities are concerned about traffic accidents on major roads. They would like
to have ambulances stationed at road intersections to quickly reach the scene of any
accident along these roads. To minimize response time, ambulances are to be located
at intersections with traffic lights so that any segment of road can be reached by at
least one ambulance that does not have to pass through a traffic light to reach the
scene of the accident. If we model the road network as a graph, where intersections
with traffic lights are vertices and edges represent road segments between traffic lights,
the graph theoretic question to be answered is:

(a) Find a spanning tree with minimum number of edges.


(b) Find a spanning tree with minimum cost.
(c) Find a minimal colouring.
(d) Find a minimum size vertex cover.

Answer: (d) Find a minimum size vertex cover.

Each ambulance “covers” the adjacent roads, and all roads are covered in this way. a

5. Let G be an arbitrary graph on n vertices with 4n − 16 edges. Consider the following


statements:

I There is a vertex of degree smaller than 8 in G.


II There is a vertex such that there are less than 16 vertices at distance exactly 2
from it.

Which of the following is true:


(a) I only (b) II only
(c) Both I and II (d) Neither I nor II

2
Answer: (a) I only

By the Pigeonhole Principle, there is a vertex of degree < 8.


As a counterexample to II, take, for instance a cycle on n − k vertices u1 , . . . , un−k (k
to be fixed). Take a vertex v0 and connect it to all the n − k cycle vertices to obtain
a wheel with n − k + 1 vertices. Now take k − 1 vertices v1 , . . . , vk−1 . For each i in
[1, . . . , k − 1] connect vi to k + 3 equally spaced vertices Cvi on the cycle so that Cvi
is connected to ui , ui+b((n−k)/(k+3)c , . . ..
Thus there are (n − k) + 1 + (k −p1) = n vertices and (n − k) + (n − k) + (k − 1)(k + 3) =
2n − 3 + k 2 = 4n − 16 for k = (2n − 13)
Each ui is at distance exactly 2 from each of its non-neighbours on the cycle (via
v0 ) for (n − k − 3) = Ω(n) vertices at distance 2. Each vj is at distance exactly 2
from at least all the other vk vertices (plus at least 2kui vertices if j 6= 0) for at least
k − 1 = Ω(sqrt(n)) vertices at distance 2. a

6. What does the following function compute in terms of n and d, for integer values of
d? Note that the operation / denotes floating point division, even if the arguments
are both integers.

function foo(n,d){
if (d == 0){
return 1;
}else{
if (d < 0){
return foo(n,d+1)/n;
}else{
return n*foo(n,d-1);
}}}

(a) logd n if d < 0, nd if d > 0.


(b) nd for all values of d.
(c) n × d if d > 0, n ÷ d if d < 0.
(d) n × d for all values of d.

Answer: (b) nd for all values of d.

For d > 0, this computes nd by repeated multiplication. For d negative, the answer is
1
nd
by repeated division. a

7. Consider the following functions f() and g().

3
f(){ g(){
w = 5; z = w+1;
w = 2*z + 2; z = 3*z - w;
} print(z);
}

We start with w and z set to 0 and execute f() and g() in parallel—that is, at each
step we either execute one statement from f() or one statement from g(). Which of
the following is not a possible value printed by g()?
(a) -2 (b) -1 (c) 2 (d) 4

Answer: (c) 2 a

The possible values are : {-1,-2,3,4,7,13}, corresponding to the interleavings below.

w = 5; w = 2*z + 2; z = w+1; z = 3*z - w: --- z = 7


w = 5; z = w+1; w = 2*z + 2; z = 3*z - w; --- z = 4
w = 5; z = w+1; z = 3*z - w; --- z = 13
z = w+1; z = 3*z - w; --- z = 3
z = w+1; w = 5; z = 3*z - w; --- z = -2
z = w+1; w = 5; w = 2*z + 2; z = 3*z - w; --- z = -1

8. A stable sort preserves the order of values that are equal with respect to the comparison
function. We have a list of three dimensional points
[(7, 1, 8), (3, 5, 7), (6, 1, 4), (6, 5, 9), (0, 2, 5), (9, 0, 9)].
We sort these in ascending order by the second coordinate. Which of the folllowing
corresponds to a stable sort of this input?

(a) [(9, 0, 9), (7, 1, 8), (6, 1, 4), (0, 2, 5), (6, 5, 9), (3, 5, 7)]
(b) [(0, 2, 5), (3, 5, 7), (6, 1, 4), (6, 5, 9), (7, 1, 8), (9, 0, 9)]
(c) [(9, 0, 9), (7, 1, 8), (6, 1, 4), (0, 2, 5), (3, 5, 7), (6, 5, 9)]
(d) [(9, 0, 9), (6, 1, 4), (7, 1, 8), (0, 2, 5), (3, 5, 7), (6, 5, 9)]

Answer: (c) [(9, 0, 9), (7, 1, 8), (6, 1, 4), (0, 2, 5), (3, 5, 7), (6, 5, 9)]

In a stable sort, the original order of the pairs (7,1,8),(6,1,4) and (3,5,7),(6,5,7) with
equal second coordinates must be preserved in the sorted output.
a

4
9.
15
Suppose we constructed the binary
search tree shown at the right by start-
ing with an empty tree and inserting 7 28
one element at a time from an input se-
quence, without any rotations or other
manipulations. Which of the following 3 12 19 37
assertions about the order of elements
in the input sequence cannot be true?
1 6 8 14 16 23 29 42

(a) 8 came after 3 and 19 came after 29.


(b) 7 came before 8 and 23 came after 37.
(c) 1 came after 12 and 29 came before 42.
(d) 3 came before 14 and 16 came before 28.

Answer: (d) 3 came before 14 and 16 came before 28.

28 is an ancestor of 16, so 16 must have come after 28. In the tree only ancestor-
descendant relationships matter in determining the order in which elements arrive.
An ancestor must always come before any of its descendants. Incomparable elements
could come in any order. a

10. We have constructed a polynomial time reduction from problem A to problem B.


Which of the following is a valid inference?

(a) If the best algorithm for B takes exponential time, there is no polynomial time
algorithm for A
(b) If the best algorithm for A takes exponential time, there is no polynomial time
algorithm for B.
(c) If we have a polynomial time algorithm for A, we must also have a polynomial
time algorithm for B.
(d) If we don’t know whether there is a polynomial time algorithm for B, there cannot
be a polynomial time algorithm for A.

Answer: (b) If the best algorithm for A takes exponential time, there is no
polynomial time algorithm for B.

If we have a polynomial time solution for B, the reduction gives us a polynomial time
solution for A.
a

5
Part B
1. Let Σ = {a, b, c}. Let Leven be the set of all even length strings in Σ∗ .
(a) Construct a deterministic finite state automaton for Leven .
(b) We consider an operation Eraseab that takes as input a string w ∈ Σ∗ and erases
all occurrences of the pattern ab from w. Formally, it can be defined as follows:
(
w if w does not contain the pattern ab
Eraseab (w) :=
Eraseab (w1 ) Eraseab (w2 ) if w = w1 ab w2 for some w1 , w2 ∈ Σ∗
For instance, Eraseab (cacb) = cacb, Eraseab (cabcbab) = ccb and Eraseab (ab) = .
For a language L, we define Eraseab (L) to be the set of strings obtained by applying
the Eraseab operation to each string in L:
Eraseab (L) := {Eraseab (w) | w ∈ L}

Show that Eraseab (Leven ) is a regular language.

Answer:
(a) Leven can be recognized by an automaton with two states {q0 , q1 }, where q0 is both
an initial and final state. On input letters a and b, the automaton switches from
q0 and q1 and vice versa. An odd length input will take the automaton to q1 and
an even length input will take the automaton to q0 .
(b) Eraseab (Leven ) is the set of all even length strings which do not contain ab.
It is easy to construct a nondeterministic automaton with three states {q0 , q1 , q2 }
for the language Lab consisting of all strings containing ab. Here, q0 is the initial
state and q2 is the final state. There is a self loop on {a, b} at both q0 and q2 and
a b
there are transitions q0 →− q1 and q1 → − q2 .
Since Lab is regular, so is its complement Lab , the language of all strings without
ab.
Eraseab (Leven ) is the intersection of Lab with Leven .
a

2. There are a number of tourist spots in a city and a company GoMad runs shuttle
services between them. Each shuttle plies between a designated origin and destination,
and has a name. Due to lack of coordination, the same name may be allotted to
multiple routes.
To make matters worse, another company GoCrazy introduces its shuttle services
using the same set of shuttle names. A GoMad shuttle and a GoCrazy shuttle with
the same name may start at different origins and/or end at different destinations.
A pass from a company allows unlimited travel in all the company’s shuttles. For each
company, we have a list that specifies all routes allotted to each shuttle name.
Design an algorithm to find out if there is a source s, a target t, and a sequence of
shuttle names σ such that, irrespective of whether you are carrying a GoMad pass or
a GoCrazy pass, you can start at s and arrive at t using the sequence σ.

6
Answer: Create a graph where the set of vertices are pairs (Spot 1, Spot 2) of tourist
spots. There is an edge labeled “Name 1” from (Spot 1, Spot 2) to (Spot 3, Spot 4)
iff there is a GoMad shuttle “Name 1” from Spot 1 to Spot 3 and a GoCrazy shuttle
“Name 1” from Spot 2 to Spot 4. The answer to the question is yes iff there is a
directed path from a vertex (Spot 1, Spot 1) to a vertex (Spot 2, Spot 2). a

3. Let Σ = {a, b}. Given words u, v ∈ Σ∗ , we say that v extends u if v is of the form xuy
for some x, y ∈ Σ∗ . Given a fixed word u, we are interested in identifying whether a
finite state automaton accepts some word that extends u.
Describe an algorithm that takes as input a finite state automaton (DFA or NFA) A
over Σ = {a, b} and a word u ∈ Σ∗ and reports “Yes” if some word in the language of
A extends u and “No” if no word in the language of A extends u.
Answer: Let R be the set of states that can be reached by a path from the initial
state in A and let S be the set of states from which there is a path to one of the final
states in A.
For each pair of states (r, s) ∈ R × S, Ar,s is obtained from A by keeping the set of
states and set of transitions unchanged, but making r the unique intial state and s
the unique final state.
If u ∈ L(Ar,s ), then there must be a word xuy ∈ L(A), where x labels the path from
the initial state to r (r ∈ R is reachable from the initial state), u labels the path from
r to s, and y labels the path from s to some final state of A (s ∈ S, so such a path
must exist.)
Hence, output “Yes” if u ∈ L(Ar,s ) for some (r, s) ∈ R × S, and “No” otherwise. a

4. In a party there are 2n participants, where n is a positive integer. Some participants


shake hands with other participants. It is known that there are no three participants
who have shaken hands with each other. Prove that the total number of handshakes
is not more than n2 .
Answer: Model this as a graph problem, we are looking for a graph without a triangle.
We show that the maximum number of edges that a triangle-free graph on 2n vertices
can have is n2 .
The proof by induction on n.
The base cases n = 1, 2 are easy to see by inspection.
For the inductive step, let n ≥ 3. If the graph G has no edges then there is nothing to
prove. Otherwise, take an edge {x, y}, and consider the graph G0 on 2(n − 1) vertices
obtained by deleting both the vertices {x, y} from G.
By the inductive hypothesis, G0 has at most (n − 1)2 edges. Since graph G is triangle-
free and {x, y} is an edge in G, there is no vertex v in G0 such that both {v, x} and
{v, y} are edges in G. So the number of edges with one end-point in the set {x, y} and
the other in the set of vertices of G0 is at most the number of vertices in G0 , namely
2(n − 1).
Now the set of edges of G consists of (i) all the edges in G0 , plus (ii) the one edge
{x, y}, plus (iii) the at most 2(n − 1) edges with exactly one end-point in {x, y}. So
the number of edges of G is at most (n − 1)2 + 1 + 2(n − 1) ≤ n2 . a

7
5. An undirected graph is connected if, for any two vertices {u, v} of the graph, there is
a path in the graph starting at u and ending at v. A tree is a connected, undirected
graph that contains no cycle.

(a) A leaf in a tree is a vertex that has degree 1. Prove that if G is a tree with at
least two vertices then G contains at least two leaves.
(b) A bipartite graph is one in which the vertex set V can be partitioned into two
disjoint sets V1 and V2 so that for every edge {u, v}, u and v lie in different
partitions—that is, u ∈ V1 and v ∈ V2 or vice versa. Prove that if G is a tree
with at least two vertices, then G is bipartite.

Answer:

(a) Consider a maximal path ρ = v0 v1 . . . vk in the tree. If v0 is not a leaf, then it has
a neighbour v 6= v1 , and the path ρ can be extended to a longer one vρ since there
are no cycles. This contradicts the fact that ρ is maximal, thereby showing that
v0 is a leaf. A similar argument shows that vk is also a leaf.
(b) If we root the tree at any node, we can colour the tree level by level by alternating
two colours. This 2-colouring gives us the partition of the vertex set.

6. We are given a sequence of pairs of integers (a1 , b1 ), (a2 , b2 ), . . . (an , bn ). We would like
to compute the largest k such that there is a sequence of numbers ci1 ≤ ci2 ≤ . . . ≤ cik
with 1 ≤ i1 < i2 < ... < ik ≤ n and for each j ≤ k, cij = aij or cij = bij . Describe an
algorithm to solve this problem and explain its complexity.

Answer: Compute two arrays A and B with A[i] and B[i] giving the length of the
longest such sequence in (a1 , b1 ), . . . (ai , bi ) with ai and bi as the last elements, respec-
tively.
Note that A[1] = 1 and B[1] = 1. To compute A[i] and B[i] for i ≥ 2, we first compute
the following quantities:
(
0 if aj > ai for all j < i
αi1 =
max{ A[j] | j < i and aj ≤ ai } otherwise
(
0 if bj > ai for all j < i
αi2 =
max{ B[j] | j < i and bj ≤ ai } otherwise
(
0 if aj > bi for all j < i
βi1 =
max{ A[j] | j < i and aj ≤ bi } otherwise
(
0 if bj > bi for all j < i
βi2 =
max{ B[j] | j < i and bj ≤ bi } otherwise

Then, we get A[i] = max(αi1 , αi2 ) + 1 and B[i] = max(βi1 , βi2 ) + 1.


Arrays A and B can be computed using dynamic programming in time O(n2 ). The
required answer is the maximum over all elements A[1], . . . , A[n], B[1], . . . , B[n]. a

8
7. Consider the following function that takes as input a sequence A of integers with
n elements, A[1], A[2], . . . , A[n] and an integer k and returns an integer value. The
function length(S) returns the length of sequence S. Comments start with //.

function mystery(A, k){


n = length(A);
if (k > n) return A[n];

v = A[1];
AL = [ A[j] : 1 <= j <= n, A[j] < v ]; // AL has elements < v in A
Av = [ A[j] : 1 <= j <= n, A[j] == v ]; // Av has elements = v in A
AR = [ A[j] : 1 <= j <= n, A[j] > v ]; // AR has elements > v in A

if (length(AL) >= k) return mystery(AL,k);


if (length(AL) + length(Av) >= k) return v;
return mystery(AR, k - (length(AL) + length(Av)));
}

(a) Explain what the function computes.


(b) What is the worst-case complexity of this algorithm in terms of the length of the
input sequence A?
(c) Give an example of a worst-case input for this algorithm.

Answer:

(a) mystery(A, k) finds the k th element in A in ascending order. This is a divide-and-


conquer selection algorithm, similar to quicksort.
(b) The worst case complexity is O(n2 ) because of the fixed choice of pivot, as in
quicksort.
(c) A typical worst case input would be, for instance, where A is in ascending order
and k = n.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy