Quiz 0 - UCSD VLSI CAD Lab

CSE 101 - Winter 2014
Quiz 0 Solutions
January 15, 2014
1 Seven light bulbs are selected at random from a set of 10 light bulbs of
which 4 are defective. What is the probability that at least two of the
selected bulbs are defective?
[ 29
30 ]
Solution Three are a total of four defective and six working light bulbs.
There are three mutually exclusive ways to choose at least two defective light bulbs out of a total of seven. We can choose the light
bulbs as follows
• Two defective and five working
• Three defective and four working
• Four defective and three working
[Case 1: Two defective and five working]
We can choose two out of the four defective light bulbs and then
any five out of the remaining six working ones. This can be done in
C(4, 2) × C(6, 5) ways.
[Case 2: Three defective and four working]
In this case we can choose three out of the four defective light bulbs
and then any four out of the remaining six working ones. This can
be done in C(4, 3) × C(6, 4) ways.
[Case 3: Four defective and three working]
In this case we have to choose all four defective light bulbs and then
any three out of the remaining six working ones. This can be done
in C(4, 4) × C(6, 3) ways.
The total number of ways to choose seven lightbulbs so that there
are at least two defective ones is C(4, 2)×C(6, 5)+C(4, 3)×C(6, 4)+
C(4, 4) × C(6, 3) the total number of ways to choose seven light bulbs
out of ten without any restriction is C(10, 7). The required probability is thus C(4,2)×C(6,5)+C(4,3)×C(6,4)+C(4,4)×C(6,3)
= 29/30
C(10,7)
2 [CSE21-W12] Allen, Bob, Charlie are playing darts. Allen is pretty good
and can hit the bullseye 80% of the time. However, Bob and Charlie are
not as good and they hit the bullseye 50% of the time. They each throw
1
one dart at the target. What is the probability that at most one of the
darts hits the bullseye?
[0.35]
Solution The possible cases are as follows
•
•
•
•
Only Allen hits the bullseye (Probability =0.8 ∗ 0.5 ∗ 0.5 = 0.2)
Only Bob hits the bullseye (Probability = 0.5*0.2*0.5 = 0.05)
Only Charlie hits the bullseye (Probability = 0.5*0.2*0.5 = 0.05)
No one hits the bullseye (Probability = 0.2*0.5*0.5 = 0.05)
The total probability is therefore 0.20+0.05+0.05+0.05 = 0.35
3 [CSE21-W12] A fair coin is repeatedly flipped until two consecutive Heads
occur. What is the expected number of flips until this first occurs?
[6]
Solution Now suppose y is the variable representing the expected number of tosses before a double heads occurs. When the first two tosses
are heads, then we are done already. This occurs with probability 0.25. When the first toss is a tail, we are again at the initial stage and the expected total number of tosses required in this
case is (1+y). This case occurs with probability 0.5. When the
first toss is a heads and the second is a tails, then we are again at
the initial stage and the expected number of tosses required in this
case is (2+y).This occurs with probability 0.25. Thus we get that
y = 0.25 × 2 + 0.25 × (2 + y) + 0.5 × (1 + y). this gives y = 6
4 [CSE21-W13] We want to count step-by-step paths between points with
integer coordinates. Only two kinds of steps are allowed: a right-step
which increments the x coordinate and an up-step which increments the
y coordinate. How many paths are there when there is an impassable
boulder sitting at point (4, 5) (Path cannot cross that point)? [C(20, 10)−
C(9, 4) × C(11, 5)]
Solution A path from origin to (10, 10) will require 10 up steps and 10
right steps, giving a total of C(20, 10) paths from origin to (10, 10).
The number of paths that pass through the point (4, 5) are the paths
that first reach (4, 5) and then go to (10, 10). (4, 5) can be reached
from origin in C(9, 4) ways and (10, 10) can be reached from (4, 5)
in C(11, 6) ways. The number of paths passing through (4, 5) is
thus C(9, 4) × C(11, 6). The required number of paths is therefore
C(20, 10) − C(9, 4) × C(11, 6).
5 [CSE100-SP13] Let V P
and W be two integer arrays of length one million.
n
Program A computes i=1 V (i). Program B computes W (i) = V (i)2 for
all i. Which program will be sped up more when running on a multi-core
machine?
[B]
Solution Program A can be parallelised by summing different parts of
the array in different threads and then adding the answers from the
2
different threads to get a final answer. The final joining of the threads
cannot be parallelised and thus has to be done serially.
Program B can be parallelised by evaluating different parts of the
array on different threads, however, in this case, they do not need to
communicate with each other later in the end. Thus the complete
program can be efficietly prarallelised.
6 [CSE21-W12] Find explicit solution to the recurrence:
f (n + 2) = 6f (n + 1) − 8f (n), n ≥ 0, f (0) = 0, f (1) = 1
[f (n) = 21 (4n − 2n )]
Solution The characteristic polynomial of the recurrence is x2 −6x+8 =
0 which has roots x = 4, 2. The solution is thus f (n) = a4n + b2n .
Using initial conditions we get f (0) = a + b = 0 =⇒ a = −b and
f (1) = 4a + 2b = 1 =⇒ a = 1/2, b = −1/2. Thus the final solution
is f (n) = (4n − 2n )/2
Pn
7 Find the sum i=1 i2i
[(n − 1)2n+1 + 2]
Solution S =
n
P
i2i , 2S =
i=1
n+1
P
(i − 1)2i .
i=2
We get S − 2S = −S = 2 +
n
P
2i − n2n+1 = 2n+1 − 2 − n2n+1 =
i=2
−2 − (n − 1)2n+1 =⇒ S = (n − 1)2n+1 + 2
2014
8 Find the remainder on dividing 20142014
mod 2161)
by 2161? (Hint: 20142 ≡ 2060
[1]
2014
Solution 20142 ≡ −1 mod 2161 =⇒ 20142014
mod 2161
This is true because 20142014 /2 is even.
2014
≡ (−1)2014
/2
≡1
9 Given a tree, which of the following ordering is needed to give the complete
unique structure of nodes in the tree?
• In-order
• Post-order
• Pre-order
• Any two will do
[Any two will do, In-order]
Solution For uniquely determining a binary tree, we need either in-order
and pre-order, or in-order and post-order, i.e. in-order is necessary
and it can be utilized in combination with one of the other orderings
to reconstruct the original structure of the binary tree. If a binary
3
tree is constructed using only its pre-order and post-order orderings,
then the tree obtained is isomorphic to the original binary tree from
which the orders were derived. Isomorphic trees are binary trees
which have left and right subtrees (i.e. left and right children) interchanged for one or more nodes present at any level of the tree. Both
answers (any two will do and in-order) have been given credit.
10 What is the number of nodes in a binary tree of height h?
[2h+1 − 1]
Solution Testing with small values we guess that the answer is 2h+1 − 1.
We will prove this by induction. When h = 0 this is indeed true
as there is just one root node. Now suppose it is true for h = k.
Now we create a tree of height k + 1 by joining two trees of height
k through a root node. This gives the total number of nodes =
2k − 1 + 2k − 1 + 1 = 2k+1 − 1 which is what we wanted.
11 Suppose an undirected graph has 15 vertices and 10 of the vertices have
degree 2 each. What could be a possible value of the sum of degrees of
the other five vertices?
• 10
• 5
• 15
• 25
[10]
Solution Apply the handshake lemma to see that the sum of the degrees
of all nodes of the graph must be even. Thus, as ten of the nodes
have degree two each, then the sum of the degrees of the remaining
five nodes must be even too. The only possible option is 10. Hence
option A is correct.
12 In a connected graph containing n vertices, any two vertices are connected
by exactly one path. How many edges can the graph have?
[n − 1]
Solution The condition is one of the if and only if conditions for a graph
G to be a tree. Hence G is a tree and has n − 1 nodes.
We will show that the stated properties (connected, only one path)
imply the graph G has no cycles. Suppose the graph has a cycle.
Let u, v be any two distinct points on this cycle. Then there are two
paths connecting u and v, one from u to v and another from v to u.
This is a contradiction and hence the graph cannot have any cycles.
In fact, any two of the properties (connected, any pair of nodes having
exactly one path, exactly n − 1 edges) imply the third.
4