Pgcs 2023
Pgcs 2023
Part A has 10 questions of 3 marks each. Each question in Part A has four choices, of which
exactly one is correct. Part B has 7 questions of 10 marks each. The total marks are 100.
Answers to Part A must be entered directly on the computer.
In all questions related to graphs, unless otherwise specified, we use the word “graph”
to mean an undirected graph with no self-loops, and at most one edge between any pair of
vertices.
Part A
1. A candy factory uses 5 fruit flavours {A, B, C, D, E}. Each candy is made using one or
more of these flavours. The taste of a candy depends on which flavours are included.
A kid may prefer some combination of flavours more than others. For example, the
kid may prefer the combination {A, B, C} over {B, C}. The preference order of a kid
is a total ordering of all the combinations, the ones occurring earlier being preferred
more.
Suppose you want to throw a party and do not want more than one kid with the same
preference order. What is the maximum number of kids that can attend such a party?
(a) (2(5!) ) − 1
(b) ((25 ) − 1)!
(c) ((5 ∗ 4)/2) − 1
(d) 5 ∗ 5
(a) 2n−1
(b) 3n
(c) 2n+1
(d) 22n
3. At a kindergarten, 2024 kids sit in a circle. Suddenly, each kid randomly pokes either
the kid to their left or the one to their right with equal probability. What is the
expected number of unpoked kids?
(a) 1
(b) 253
(c) 506
(d) 1012
1
4. A graph is k-regular if all the vertices have degree exactly k. What is the minimum
number of vertices in a k-regular graph that has no 3-length cycles?
(a) k
(b) k + 1
(c) 2k
(d) 2k + 1
(a) have at least one vertex in common, but not necessarily an edge in common
(b) have at least one edge in common
(c) have at least two common vertices, but not necessarily an edge in common
(d) have at least two edges in common
6. Consider the automaton over the alphabet {a, b, c} shown in Figure 1. The initial
state is the leftmost state. States with a double circle are accepting states.
a, b
a, b
b, c
b, c
c, a
c, a
(a) {}
(b) c∗ + a∗ + b∗
(c) (a + b)∗ + (b + c)∗ + (c + a)∗
(d) None of the above
7. Let L be a regular language, and let n = 10. Which of the following statements is
true?
2
8. Let f : N → N and g : N → N be functions over the set N of natural numbers. We
will say:
• f (n) = O(g(n)) if there exist natural numbers c and x0 such that f (n) ≤ c g(n)
for all n ≥ x0
• f (n) = 2O(g(n)) if there exist natural numbers c and x0 such that f (n) ≤ 2(c g(n))
for all n ≥ x0 .
Questions 9 and 10 refer to the following two functions. We assume that all the arguments
are non-negative integers. The operation x div 2 divides x by 2 and returns an integer,
discarding the fractional part.
(a) 2
(b) 5
(c) 6
(d) 10
(a) 3
(b) 9
(c) 12
(d) 15
3
Part B
1. Let Σ = {a, b} be an alphabet. A palindrome is a word which reads the same when
read from left-to-right, or from right-to-left. For example, the words abba, aba and aa
are palindromes, whereas aabb and ab are not. A palindrome is said to be non-trivial
if it has length at least 2.
Let L be the set of all words that contain a non-trivial palindrome as a prefix, that is,
4. On the island of Knights, Knaves, and Normals, Knights always tell the truth, Knaves
always lie, and Normals sometimes tell the truth and lie sometimes.
One day Professor Raymond visited this island and met two inhabitants, A and B.
He already knew that one of them was a Knight and the other was a Normal, but
he didn’t know which was which. He asked A whether B was normal, and received
a Yes-or-No answer. Professor Raymond was then able to figure out who the Knight
was.
Who was the Knight – A or B?
4
5. You are starting a new bus service. You are hiring drivers and conductors. A driver
and a conductor can run a bus only if they can speak a common language. There
are n drivers and m conductors who have applied for a job. Their CV has a list of
languages they speak.
(a) Given the CVs of the drivers and conductors, we want to calculate the maximum
number of buses that can be run. Show how to use graph matching to solve this
problem. (Note: You do not need to solve graph matching itself. Just demonstrate
how to use it for this problem.)
(b) You are in a hurry to get the bus service running. Whenever you get a new
application from a driver (or a conductor), you check if you can team this new
candidate with an existing conductor (or driver) who is free. If yes, you assign the
pair of them to a bus. If no, then the new candidate is added to the list of free
driver (or conductors).
Provide an example scenario where the above procedure does not compute the
maximum number of buses that can be run.
6. The input to the problem consists of (i) an array A[1, 2, . . . , n] of n positive integers
and (ii) a positive integer T . We are given the guarantee that at least one element
of the array is less than or equal to T . The task is to find the maximum sum of a
non-empty sub-collection of the integers from A which is less than or equal to T .
Describe an algorithm that solves this problem in O(nT ) time. The algorithm should
take an array A[1, 2, . . . , n] and an integer T as described above, and should output
a number T 0 ≤ T that is closest to T and can be realized as the sum of some sub-
collection of A. It is not required that the algorithm find the subset of indices which
forms the sum T 0 .
7. Consider the following code which computes a function f. The input to f is an array
A[1..m] which represents a number N in ternary. For example, A = [1, 2, 0] repre-
sents the number 15 since 15 = 1 ∗ 32 + 2 ∗ 31 + 0 ∗ 30 ; and A = [1,0,0,0] represents
the number 27. Function f uses the function pow(x,y) that returns xy . You may
assume that the first element in the array is not zero.
int f(A[1..m]) {
x = 1;
for j = 1 to m {
x = pow(x, 3);
y = pow(3, A[j]);
x = x * y;
}
return x;
}