Mscds2022 Solutions
Mscds2022 Solutions
Mscds2022 Solutions
Part A - Answers
Solution: Choices (a) and (c) are correct, and choices (b) and (d) are wrong. These follow from straight-
forward computation using standard formulas.
2. Consider the following code, in which A is an array indexed from 0 and n is the number of elements in A..
function foo (A , n ) {
L = 0;
R = n - 1;
while ( L <= R ) {
i = ceil (( L + R )/2);
if ( A [ i ] < i ) {
L = i + 1;
} else {
if ( A [ i ] > i ) {
R = i - 1;
} else {
return ( i );
}
}
}
return ( -1);
}
Here, ceil(x) returns the smallest integer bigger than or equal to the number x.
If A = [-5, -4, -3, -2, -1, 4, 6, 8, 10, 12], what will foo(A, 10) return?
(a) -5
(b) -1
(c) 4
(d) 6
Solution: Choice (d) is correct. Given a sorted array A with distinct integers and the length of A as
arguments, this function nds an index i such that A[i] = i, or returns -1 if there is no such index i.
Since there is exactly one such index, namely 6, this is what we get back.
Solution:
Choices (b) and (d) are correct, and choices (a) and (c) are wrong.
• (a) is wrong: This is a GP series. For |r| > 1 the limit is divergent.
(eix −e−ix ) (eix +e−ix )
• (b) is correct: Since e−ix = cos x − i sin x, we have sin x = 2i , and cos x = 2 .
• (c) is wrong:
∞
X
1 1 1 1
+ + + ··· =
1.2 2.3 3.4 n(n + 1)
n=1
X
n
1
= lim
n→∞ k(k + 1)
k=1
hX n
1 1 i
= lim −
n→∞ k k+1
k=1
h 1 1 1 1 1 i
= lim 1 − + − + · · · + −
n→∞ 2 2 3 n n+1
h 1 i
= lim 1 − = 1.
n→∞ n+1
Z π/6 " #π/6
1 3π π
• (d) is correct: 3 cos 3x ≥ 0 ∀x ∈ (0, π/6), and 3 cos 3x dx = 3 sin 3x = sin = sin = 1.
0 3 6 2
0
4. Let E and F be events such that P(E ∩ Fc ) = 0.2, P(F ∩ Ec ) = 0.3, P((E ∩ F)c ) = 0.7, where, for an event E, the
notation Ec denotes the complement of the event. Then we can conclude that
(a) P(E ∪ F) = 0.8.
(b) P(Ec ∩ Fc ) = 0.3.
(c) P(F) = 0.6.
(d) P(E) = 0.6.
Solution: Choices (a) and (c) are correct, and choices (b) and (d) are wrong. These follow from straight-
forward computation, e.g., by using a Venn diagram.
5. Let A, B be n × n invertible matrices of real numbers. Let C = I + AAT , D = I + BAAT BT . We can conclude
that
(a) (AB)−1 = (I + B−1 A−1 )
(b) (AB)−1 = A−1 B−1
(c) C = CT
(d) D = DT
Solution: Choices (c) and (d) are correct, and choices (a) and (b) are wrong. These follow by straight-
forward computation using standard properties of matrices.
6. A matrix C is said to be symmetric if CT = C. Which of the following is/are true? Let A, B be n × n matrices.
(a) If A is symmetric and invertible, then A−1 is also symmetric and invertible.
(b) If A and B are symmetric, then C = AB is also symmetric.
(c) If A and B are invertible, then C = AB is also invertible.
(d) If A and B are symmetric, then D = A + B is also symmetric.
Solution: Choices (a), (c) and (d) are correct, and choice (b) is wrong. These follow from standard
properties of matrices.
Solution: Choice (d) is correct, and choices (a), (b) and (c) are wrong:
• (a) is wrong: If A is all zeroes, then Ay = 0 for any vector y, and A is clearly not full rank.
• (b) is wrong: Let the rst m rows of A be identical to the m × m identity matrix, and let the
remaining rows be all zero. Then there is no such nonzero solution y.
• (c) is wrong: Consider
I5
.
0
This matrix has n = 6, m = 5, and row and column ranks both equal to 5.
• (d) is correct: The rank of A is the least such r.
8. Let n ≥ 5 be a natural number, let X = {x1 , x2 , ..., xn }, and let Y = {y1 , y2 }. Let F be the set of functions from
X to Y and G be the set of bijective functions from X to Y . Then
Solution: Choices (b) and (d) are correct, and choices (a) and (c) are wrong:
• (c) is wrong: Since X, Y have dierent cardinalities, there are no bijections from X to Y .
9. In order to select a debating team to represent a school, 7 students from class XII and 13 students from class
XI were shortlisted and were undergoing trials. The coach had to select a team of 5 students, out of which at
least two students should be from each class. One out of the 5 students was to be named as team leader, who
was to be from class XII. Two teams with the same members but dierent leaders are considered to be two
dierent teams. The number of dierent teams the coach can select is
7 13 7 13
(a) 2 × × + ×
2 3 3 2
7 13 7 13
(b) × + ×
2 3 3 2
7 13 7 13
(c) 2 × × +3× ×
2 3 3 2
7 13 7 13
(d) 3 × × +2× ×
2 3 3 2
Solution: Choice (c) is correct, and choices (a), (b) and (d) are wrong.
Any choice of team either has exactly 2 students from class XII and exactly 3 students from class XI, OR
it has exactly 3 students from class XII and exactly 2 students from class XI. The two terms in the sum
in choice (c) correspond to these two cases.
For each choice of k ∈ {2, 3} students from class XII, there are k ways of choosing the leader. This is the
leading term in each product in choice (c).
Here is an alternate derivation: There are 7 ways of selecting a leader. For each leader selected, we can
now pick either a single student from class XII or two students from class XII and the rest need to be from
class XI. To form a team by selecting a single non-leader student from class XII, there are 7 · 61 · 133
ways. To form a team by selecting exactly two non-leader class XII students, there are exactly 7 · 62 · 132
ways. The answer is the sum of these.
10. Which of the following plots correspond to a function whose derivative is continuous?
I. I
I Ciii)
t ( in
0 . I 0
I 1
Liii) ( ir)
12. A relation R on the set A = {a, b, c, d} is dened by reading the columns of the following table from top to
bottom. If a column in the table reads (x, y, 1) it means x is related to y in R. If a column in the table reads
(x, y, 0) it means x is not related to y.
a b c d a b c d a b c d a b c d
a a a a b b b b c c c c d d d d
0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0
For instance, from the fth column we have, (a, b) ∈ R, and from the second we have (b, a) ∈/ R.
Another relation S on the set A is dened as: for any x, y ∈ A, the pair (x, y) is in S if and only if there exists
z ∈ A such that both (x, z) ∈ R and (z, y) ∈ R hold.
Which of the following pairs are in S?
(a) (a, a)
(b) (b, b)
(c) (c, c)
(d) (d, d)
Solution:
Choices (a), (c), and (d) are correct, and choice (b) is wrong:
13. We say that a subset S of a nite set U is large if |S| > |U \ S|. Here U \ S denotes the elements of U which
are not in S and the notation |T | denotes the number of elements in a set T . Let x be the number of large
subsets of the set X = {1, 2, . . . , 10}, and let y be the number of large subsets of Y = {1, 2, . . . , 9}. Which of the
following is true?
(a) x = 260, y = 256
(b) x = 386, y = 256
(c) x = 386, y = 130
(d) x = 512, y = 256.
14. A ternary tree starts with a single root node at the top of the tree. Each node in the tree can have up to three
nodes as its children. No node in the tree is the child of two dierent nodes. A node which has no children is
called a leaf node.
The children of a node are drawn below it, connected by edges. The level of a node v in the ternary tree is
the number of edges in the (unique) path from the root node to v. Thus, for instance, the root node is at
level 0, and each child of the root node is at level 1.
A complete ternary tree is a ternary tree in which (i) each non-leaf node has exactly three children, and (ii)
all leaf nodes are at the same level. This latter level is called the height of the complete ternary tree. The
completeNternary trees of heights 0, 1, and 2, respectively are shown in the gure below, where we use the
symbol to denote a node:
N N N
N N N
N N N
N N N N N N N N N
(c) 310 −1
2
(d) 310 +1
2
Solution: Choice (c) is correct: the number of nodes is the value of the sum 1 + 31 + 32 + . . . + 39 .
Choices (a), (b), (d) are wrong.
15. Which of the following expressions take integral values for all integers n > 100 ?
(a) 3n −1
2
(b) 4n −1
2
(c) 4n −1
3
(d) 5n −1
2
Solution:
Choices (a), (c) and (d) are correct, and choice (b) is wrong:
16. At a conference attended by 1235 people, some attendees shake hands with other attendees. As a part of the
local COVID-19 tracing protocol the organizers ask each attendee to note down the number of other attendees
with whom they shook hands. Let N be the sum of all the numbers noted down by the attendees. That is, N
is the sum, taken over all attendees, of the number of other attendees with whom they shook hands. Which
of the following is guaranteed to be true about N ?
(a) N is always a multiple of 1235
(b) N is always a multiple of 2
(c) N is always a multiple of 3
(d) N is always a multiple of 5
Solution: The only correct choice is (b): Each handshake adds 2 to N , so N must be an even number.
17. Let n be a positive integer and let k be a positive integer which is greater than 1. Then n can be represented
as
n = nt kt + nt−1 kt−1 + · · · + n1 k + n0
for a unique set of positive integers n0 , . . . nt . This expression is called the representation of n in base k and is
denoted by (nt nt−1 . . . n0 )k . For example the integer 264 expressed in base 3 is represented as (1 0 0 2 1 0)3
because 264 = 1 × 35 + 2 × 32 + 1 × 3.
Which of the following expressions represent the integer (1 1 0 1 1 1 1 0)2 ?
(a) (1 1 0 0)8
(b) (1 3 4 2)5
(c) (4 3 2)7
(d) (2 2 0 2 0)3
Solution: Choices (b) and (d) are correct, and choices (a) and (c) are wrong. The given integer, in
decimal notation, is 222.
18. There are two villages X and Y in a faraway land. It is known that each person from village X always tells the
truth, and that each person from village Y always lies.
You meet three people A, B, C who are from these villages. You are told that A and B are from the same
village. A says, \If B is from village X, then I am from village Y ". Now C says, \If I am from village X, then
2 + 2 = 4".
What can you infer about the villages to which A, B, and C belong?
(a) A, B are from village X and C is from village Y .
(b) All three of them are from village Y .
(c) A, B are from village Y and C is from village X.
(d) The given information is insucient to infer the villages to which A, B, C belong.
19. A stick is xed on the ground at an angle of 60 degrees as shown in Figure 1. The part of the stick which is
above the ground|which is the part that is shown in Figure 1|has a length of 10 metres. At a certain time
T1 during the day, the sun is directly overhead at this location and its rays strike the ground at an angle of
90 degrees. This is shown in Figure 2. At a certain later time T2 the sun's rays strike the ground at an angle
of 60 degrees as shown in Figure 3. While Figures 2 and 3 show only the sun's rays for the sake of clarity, the
stick is present at this location at times T1 and T2 .
Sunrays Sunrays
Stick
60° 60°
90°
What are the lengths of the shadows of the stick at times T1 and T2 , respectively?
√ √
(a) 5 3 metres and 10 3 metres
√
(b) 5 metres and 10 3 metres
(c) 5 metres and 10 metres
√
(d) 5 3 metres and 10 metres
20. A park in Chennai has walkways as depicted in the gure. The straight path from A to B is 100 metres long.
The curved part is a semicircle whose centre coincides with the midpoint of line segment AB.
A B
A woman and her dog take a walk in this park, both starting from point A at the same time. The woman
takes the straight path from A to B, while the dog goes around the semicircular path. The woman and the
dog both reach point B at the same time. If the woman takes 10 minutes to reach from point A to point B,
which of the following statements about the woman's and dog's walks is/are true?
(a) The average speed of the woman's walk is between 0.15ms−1 and 0.17ms−1
(b) The average speed of the woman's walk is between 0.17ms−1 and 0.20ms−1
(c) The average speed of the dog's walk is between 0.25ms−1 and 0.27ms−1
(d) The average speed of the dog's walk is between 0.27ms−1 and 0.30ms−1
Solution: Choices (a) and (d) are correct, and choices (b) and (c) are wrong:
• The length of the semicircular path is π × 50m ≈ 157m, with π ≈ 3.14. The average speed of the
dog's walk is thus ≈ 157m
600s ≈ 0.262ms .
−1
Note that to get these answers right it is enough to compute that 0.15 < 16 < 0.20, and 0.25 < 160
600 < 0.3.
Part (B) – Short-answer questions
For questions in part (B), you have to write your answer with a short explanation in the space provided
for the question in your answer sheet. If you need more space, you may continue on the pages provided for
rough work. Any such over
ows must be clearly labeled.
1. There are three dierent approaches that climbers can take to reach the summit of Mount Cherno, namely,
Approach-I, Approach-II, and Approach-III. Each attempt at the summit uses exactly one of these
approaches. From climbers' logs it is known that Approach-I is used in 40% of the attempts, and Approach-
II and Approach-III are each used in 30% of the attempts. From the same logs it is also known that in 10%
of the attempts which used Approach-I the climber lost their way and had to be rescued. Similarly, 15%
of the attempts that used Approach-II and 17% of the attempts which used Approach-III resulted in the
climber losing their way.
It is reported one day that climber Chebyshev has lost her way. What is the probability that she took
Approach-II?
Solution: 0.045
0.136 ≈ 0.3308824 .
The following information is given in the description:
• P(Approach-I) = 0.4 • P(Approach-II) = 0.3 • P(Approach-III) = 0.3
• P(lost | Approach-I) = 0.1 • P(lost | Approach-II) = 0.15 • P(lost | Approach-III) = 0.17
Now,
P(lost) = P(lost | Approach-I)P(Approach-I)
+ P(lost | Approach-II)P(Approach-II)
+ P(lost | Approach-III)P(Approach-III)
Hence
0.15 ∗ 0.3
P(Approach-II | lost) = ≈ 0.3308824
0.136
2. Express the total service outage caused by all the three servers, as a percentage of the total duration over
which the information was collected.
Solution: 2.8% .
The following information is given in the description:
3. What is the expected number of hours of service outage in an year (365 days)?
4. As part of their due diligence, a potential customer of Dasholytics picks a random point in time during the
year and checks the status of the dashboard. What is the probability that the customer nds that there was
a service outage at this point in time, and that Server 1 was the server responsible for serving data at that
time?
Solution: 0.004 .
The chance of service outage due to Server 1 is
P(Outage and Server 1) = P(Outage | Server 1) × P(Server 1) = 0.01 × 0.4 = 0.004,
5. An alert that a service outage has been caused by one of the three servers, was sent out to the Dasholyltics
team. What is the probability that this outage was caused by Server 1?
6. In a question paper, there are 5 questions in part A, 4 in part B, and 3 in part C. In how many ways can a
candidate make up her choice, if she has to select 3 from part A, 2 from part B, and 2 from part C?
Solution: 180
The possible number of selections is
5 4 3 5×4×3 4×3 3×2
× × = × × = 180.
3 2 2 3×2 2×1 2×1
Let X be a random variable with mean E(X) = µPand variance Var(X) = σ2 . Let X1 , X2 , . . . , Xn be n
independently sampled values of X, and let X = n1 i Xi be the sample mean. The central limit theorem
states that if the sample size n is large enough then X approximately follows the normal distribution with
mean µ and variance σ2 /n. That is, X ≈ N(µ, σ2 /n). This in turn implies that
√
− µ)
n(X
Y= ≈ N(0, 1).
σ
Let Z be a random variable that follows the normal distribution with mean 0 and variance 1. For any real
number a let Φ(a) = P(Z < a) be the probability that Z takes values smaller than a. Then
Za 2
e−u /2
Φ(a) = P(Z < a) = √ du.
−∞ 2π
For solving the next two problems you may assume the following approximations: Φ(−2) = 0.02, Φ(−1) =
0.16, Φ(0) = 0.5, Φ(1) = 0.84, Φ(2) = 0.98.
The weekly number of sales S at a certain car dealership is known to follow a probability distribution with
mean E(X) = 10 and variance Var(X) = 144. A performance audit picks a random sample of 36 weekly sales
gures S1 , S2 , . . . , S36 from the last two years. They nd that the sample mean is 10 and the sample variance
is 144. Use this information to answer the next two questions. You may assume that n = 36 is a large enough
sample size.
7. (a) What is the probability that the average number of sales in a week will be more than 8?
Solution: 0.84
Note that X ≈ N(10, 2), where µ = 10, σ = 12, and n = 36. So we have
√36(X
− 10)
√
36(8 − 10)
> 8) = P
P(X >
12 12
6 × −2
= P Z> = P(Z > −1) = 1 − P(Z < −1)
12
= 1 − Φ(−1) = 1 − 0.16 = 0.84.
(b) What is the total number of sales over the 36 weeks which were sampled?
Solution: 360
The average sales per week is 10, i.e., X = 10 . Since the number of weeks n = 36, the total sales is
P
Xi = n × X = 36 × 10 = 360.
8. Check if the following statement(s) are correct. Brie
y explain your reasons.
(a) The probability that the average number of sales in a week will be more than 8 but less than 14 is
Z 14
1 u−10 2
√ e−0.5( 12
)
du
8 12 2π
(b) The probability that a salesperson would be able to sell ten or more products in a week is 50%.
Solution: Correct.
It is given that the weekly average sales follows a normal distribution with mean 10. The probability
that the weekly average sales is at least the mean, is half.
9. Two particles move in opposite directions around a circular track. The rst moves at a constant speed of 10
m/s. The speed of the second increases at a constant rate of 2 m/s every second. The particles are at the
same position A at time 0, with the second particle being momentarily at rest at t = 0. We are told that
the second meeting of these particles after time 0 takes place at the point A. We assume that the particles
magically cross each other the rst time they meet with no change in their instantaneous velocities. Given
this information:
(a) What is the circumference of the track?
(b) At what time did the particles meet for the rst time after time 0?
√ √ √
Solution: ( 125 − 5) = (5 5 − 5) = 5 ∗ ( 5 − 1) ≈ 6.18 seconds.
√ √
Solving 100 = 10t1 + t21 , we get t1 = (−10 + 500)/2 = 5 ∗ ( 5 − 1).
10. Words are formed using the characters 0 and 1. The length of a word is the number of characters in it. We
say there is a path from word x to word y if starting from the word x you can get the word y by applying the
following sequence of transformation rules nitely many times in any order.
• Replacing an occurrence of the string 101 by a 0.
• Replacing an occurrence of the string 010 by a 1.
• Replacing a 0 by a 101.
• Replacing a 1 by by a 010.
If there is a path from word x to word y we say x and y are equivalent or that they are in the same equivalence
class. For example the four letter word 1011 is equivalent to the two letter word 01, since the prex 101 in
1011 can be replaced by a 0 to get 01.
We say x has a shorter description if there is a word of shorter length equivalent to it.
(a) State true or false: for any word x there is a unique shortest word in its equivalence class.
Solution: False.
E.g.: 1010 ≡ 11, and 1010 ≡ 00.
(b) How many three letter words are there in this language which have no shorter descriptions and which
are all in dierent equivalance classes?
11. You are given an 8 × 8 chessboard and a large supply of T -shaped tiles and square-shaped tiles of the kind
shown below.
Note that the squares in these two shaped tiles are of the same size as the black/white squares on the
chessboard.
We wish to cover the squares of the chess board using these tiles. Each square of the chessboard must be
occupied by exactly one square from a tile; we are not allowed to break the tiles.
(a) Is it possible to cover the chessboard with 16 T shaped tiles? Why?
Solution: Yes.
Greedy tiling will work for a 4 × 8 grid, by trial and error. Doing this twice will cover the entire chess
board.
(b) Is it possible to cover the chessboard with 15 T shaped tiles and one square tile? Why?
Solution: No.
Note that a square tile occupies two black and two white squares on the chessboard. So 15 square
tiles occupy 30 black and 30 white squares in total. There are two white and two black squares left
to cover. A T-shaped tile occupies either 3 black squares and a white square, or 3 white squares and
a black square. So we cannot cover the remaining four squares with a T-shaped tile.
12. To guard against login attempts by bots, Alphabet Bank of India uses a captcha challenge on their net banking
login page. The captcha text is a sequence of ve letters from the English alphabet.
(a) An early version of the captcha text consisted of a sequence of ve distinct letters picked uniformly at
random from the lower-case English alphabet, {a, b, c, . . . , z}. Two examples of such captcha text are:
qfhdk and smgft. An example of such captcha text which has its rst two letters in increasing alphabetical
order is: vxztr.
What is the probability that the captcha text generated in this way has the first two letters in
increasing alphabetical order, and why?
1
Solution: 2
One way to see this is as follows: construct a bijection between strings that have their rst two letters
in alphabetic order, and those which don't. That is: let xyZ be a captcha text, where x, y stand for
some one letter each, and Z stands for the remaining three letters. The bijection maps xyZ to yxZ,
and exactly one of these two strings has its rst two letters in alphabetical order. So the number of
captcha texts with the desired property is exactly half the total number of captcha texts.
(A solution which explicitly computes the fraction of favourable sequences over all possible sequences,
and evaluates to half, is also valid.)
(b) After a couple of years the bank noticed that some bots had become very good at cracking the captcha.
So they updated their software so that it now generates the captcha text by picking ve distinct letters
uniformly at random from the English alphabet, where the case of each letter can be either upper or
lower. That is, the letters are now picked from the set {a, b, c, . . . , z, A, B, C, . . . , Z}. Note that the same
letter does not appear in both lower and upper case in the same captcha text.
Two examples of the captcha text generated by this version are: QFhDk and sMgfT. Examples of such
captcha text with the rst two letters in increasing alphabetical order are: VxPTr and vXptR. Note that
the case of the letter does not matter when deciding the alphabetical order.
What is the probability that the captcha text generated in this way has the rst two letters in increasing
alphabetical order, and why?
1
Solution: 2
One way to see this is as follows: construct a bijection between strings that have their rst two letters
in alphabetic order, and those which don't. That is: let xyZ be a captcha text, where x, y stand for
some one letter each, and Z stands for the remaining three letters. The bijection maps xyZ to yxZ,
and exactly one of these two strings has its rst two letters in alphabetical order. So the number of
captcha texts with the desired property is exactly half the total number of captcha texts.
(A solution which explicitly computes the fraction of favourable sequences over all possible sequences,
and evaluates to half, is also valid.)
13. Among 40 bicycle gears, 28 are broken or rusted but not both, 6 are non-defective (i.e. neither rusted nor
broken), and the number of broken gears equals the number of rusted ones. How many gears are rusted?
Solution: 20
Let U = number of bicycle gears, B = number of broken gears, R = number of rusted gears. We are given
that |U| = 40, |B − R| |R − B| = 28, |B R| = 6 and |B| = |R|. So |B R| = 40 − 6 = 34, which implies
S S c S
14. Consider the following code, in which A and B are arrays indexed from 0 and lenA and lenB are the numbers
of elements in A and B, respectively.
function foo (A , B , lenA , lenB ) {
acc = 0;
for i = 0 to ( lenA - 1) {
acc = A [ i ]^ acc ;
}
print ( acc );
for i = 0 to ( lenB - 1) {
acc = B [ i ]^ acc ;
}
print ( acc );
}
Here, a^b represents the bitwise Exclusive OR function over variables a and b.
Given integers a and b, we write them in binary, padded by zeros to the left to make them of equal length.
We then apply Exclusive OR to these binary representations bitwise. The operation a^b denotes the in-
teger value obtained by performing bitwise Exclusive OR on the binary values of a and b. For example,
3^4 = 011^100 = 111 = 7, and 9^5 = 1001^0101 = 1100 = 12. The truth table for the Exclusive OR
function is provided.
a b a^b
0 0 0
0 1 1
1 0 1
1 1 0
Let A = [1, 3, 3, 5, 5] and B = [9, 5, 5, 3, 3, 1]. What are the two values printed by foo(A,B,5,6),
in order?
15. Consider the following code, in which A and B are arrays indexed from 0 and lenA and lenB are the numbers
of elements in A and B, respectively.
function foo (A , B , lenA , lenB ) {
sum = lenA + lenB ;
i = 0;
j = 0;
for t = 0 to ( sum - 1) {
if ( A [ i ] < B [ j ]) {
i = i + 1;
} else {
if ( A [ i ] > B [ j ]) {
j = j + 1;
} else {
return A [ i ];
}
}
}
return ( -1);
}
Let A = [2, 4, 6, 7, 8, 9, 10] and B = [1, 3, 5, 7, 9, 11, 13]. What does foo(A,B,7,7) return?
Solution: 7
Given (i) two positive integer arrays A and B, each sorted in non-decreasing order, and (ii) the lengths of
these two arrays as arguments, this function returns the smallest integer which is present in both A and B,
or −1 if there is no common element. Since the smallest common element is 7 for these arrays, the code
returns 7.
(An explanation that shows how the code runs on this particular input and returns the answer, is also
valid.)
16. Consider the following code, in which A is an integer array of length n indexed from 0, and x is an integer.
function foo (A ,x , n ) {
found = False ;
Here, randInt(0,n) returns an integer picked uniformly at random from the range {0, 1, . . . , (n − 1)}.
All integers present in array A are distinct, and integer x is present in array A. Suppose we make the call
foo(A,x,n). What is the expected number of times that the call randInd(0, n) is made from within this
call to foo(A,x,n)?
Solution: n
The probability of each call to randInd(0, n) succeeding (that is, returning an i such that A[i] == x)
is n1 . This is because there are exactly n elements in A, of which exactly one element is equal to x. So the
expected number of trials before one trial succeeds, is n.
17. A graph consists of a nite set of vertices, and edges between some (unordered) pairs of these vertices. The
graphs in this question have no loops (an edge between a vertex and itself) or multiple edges (more than one
edge between the same pair of vertices). A vertex v in a graph is said to be a global vertex if there is an edge
between v and every other vertex in the graph.
A graph G is constructed as follows: First, its vertex set is assigned to be the set {v1 , v2 , . . . , v10 }. Next,
between each pair of distinct vertices vi , vj , an edge is added with probability 12 .
(a) What is the probability that vertex v1 is a global vertex in graph G?
1
Solution: 29
All the 9 possible edges incident with v1 have to be added by the random process. The probability
of adding one of these edges is 12 . The description implies that edges are added independently of one
another. So the probability of adding all these 9 edges is 219 .
10
Solution: 29
From the previous question, the probability of each vertex being global is 219 . So the expected number
of global vertices among 10 such vertices is 10 × 219 .
Here is an alternative explanation, with more details: To each vertex, assign an indicator random
variable that takes the value 1 exactly when the vertex is a global vertex. The number of global
vertices is then the sum of these indicator random variables. The expected number of global vertices
is the expectation of this sum. By linearity of expectation, this in turn is the sum of the expectations
of the indicator random variables. The expectation of each indicator random variable is just the
probability that it takes the value 1. And this probability is 219 . So the sum of expectations is
10 × 219 .
18. The sum of two positive integers a and b is 48 and their least common multiple is 189. Find a and b.
Solution: a = 21 and b = 27
Let d denote the g.c.d. of a and b. Then there are integers m and n such that a = dm, b = dn and
g.c.d.(m, n) = 1. In that case dmn = 189 and d(m + n) = 48.
g.c.d.(m, n) = 1 implies g.c.d.(dmn, d(m + n)) = d, so d must be g.c.d.(189, 48) = 3. Then m + n = 24
and mn = 63. Together with the fact that g.c.d.(m, n) = 1, this implies that m = 7, n = 9. So a = 21
and b = 27.
19. Recall that for an n × n matrix A, det(A) = det(AT ). Here AT is the transpose of matrix A. An n × n matrix
A is said to be skew-symmetric if ai,j = −aj,i , where ai,j denotes the element in the ith row and jth column,
for all 1 ≤ i, j ≤ n and all elements are real.
(a) Is the following statement true or false? Why?
If n is odd, then the determinant of an n × n-skew symmetric matrix is 0.
Solution:
One such example:
0 1
A= .
−1 0
20. An object X is viewed from a camera placed at point C1 . The camera is then moved to the point C2 and X is
again viewed from this new position. Suppose H is the plane containing the points C1 and C2 . Let H ′ be a
plane parallel to H lying between the object X and the camera positions. Let f denote the distance between
H and H ′ . Let X1 , X2 be the points of intersection of H ′ with the line segments joining X with C1 and C2
respectively.
Let x1 be the distance between the reference axis L1 and X1 . Similarly let x2 be the distance between the
reference axis L2 and X2 . The axes L1 and L2 are both perpendicular to the camera plane H. The dierence
|x1 − x2 | is called the disparity in views. Find a formula for the depth z i.e. distance of the object from the
camera plane in terms of f, the distance b between the cameras, and the disparity.
• ✗
H
:¥ "
H
C
l
,
← b →
1
ti
Cz
:
↓ .
Z
b×f
Solution: z = |x1 −x2 |