Sunday, 10 May 2015

Question 1,paper3,June12.Consider the following pseudocode segment :


K:=0
for i1:= l to n
for i2:= 1 to i1
:
:
:
for im:= 1 to im–1
K:= K+1
The value of K after the execution of this code shall be
Options (A) C(n + m – 1, m) (B) C(n – m + 1, m) (C) C(n + m – 1, n) (D) C(n – m + 1, n) Answer(A) C(n + m – 1, m).
Explantaion
Let n=1 and m=1. So we have only one loop For i1=1 to 1. K=k+1. Answer is 1. Let n=2 and m=1 For i=1 to 2 K=k+1 answer is 2. And similarly we can say that generalized answer is C(n+m-1,m) that is equal to fact(n)/((fact(m)* fact(n-m)).

No comments:

Post a Comment

Note: only a member of this blog may post a comment.