Wednesday 27 November 2013

Question on Programming

Consider the following function


Answer : B

Explanation :

Loop A runs Log N times if you watch closely.
[ J becomes 2, 4, 8, 16, ...., 2^X. It stops when 2^X = N. That is X = Log N.]

Loop B runs for n/2 times. Each time Loop A runs it increments K by n/2.

So, value of K is approx, n/2 times the statement inside A runs.
=> n/2 * Number of times Loop B runs * Number of times Loop A runs
=> n/2 * n/2 * Log N
=> O(n^2 Log N)

Topics to revise :
C language

References :
None as of now

No comments:

Post a Comment