Sunteți pe pagina 1din 1

heap queue

level order traversal


3)An anti aircraft gun can fire four shots at a time. If the probabilities of th
e first, second, third and the last shot hitting the enemy aircraft are 0.7, 0.6
, 0.5 and 0.4, what is the probability that four shots aimed at an enemy aircraf
t will bring the aircraft down?
1. 0.084 2. 0.916
2. 0.036 4. 0.964
Correct Answer - (4)

Solution:
The enemy aircraft will be brought down even if one of the four shots hits the a
ircraft.
The opposite of this situation is that none of the four shots hit the aircraft.
The probability that none of the four shots hit the aircraft is given by (1-0.7)
(1-0.6)(1-0.5)(1-0.4) = 0.3*0.4*0.5*0.6 = 0.036
So, the probability that at least one of the four hits the aircraft = 1 0.036 = 0.
964.
1) What is the return value of f(p, p) if the value of p is initialized to 5 bef
ore the call? Note that the first parameter is passed by reference, whereas the
second parameter is passed by value.
int f(int &x, int c) {
c = c - 1;
if (c == 0) return 1;
x = x + 1;
return f(x, c) * x;
}
(A) 3024
(B) 6561
(C) 55440
(D) 161051
Answer (B)
Since c is passed by value and x is passed by reference, all functions will have
same copy of x, but different copies of c.
f(5, 5) = f(x, 4)*x = f(x, 3)*x*x = f(x, 2)*x*x*x = f(x, 1)*x*x*x*x = 1*x*x*x*x
= x^4
Since x is incremented in every function call, it becomes 9 after f(x, 2) call.
So the value of expression x^4 becomes 9^4 which is 6561.