1 votes 1 votes Correct answer is A Algorithms test-series + – nag.swarna asked Nov 6, 2018 nag.swarna 656 views answer comment Share Follow See all 13 Comments See all 13 13 Comments reply Shaik Masthan commented Nov 6, 2018 reply Follow Share what is the problem with that answer? 0 votes 0 votes Naveen Kumar 3 commented Nov 6, 2018 reply Follow Share a) i loop iterating from N to 1 and for each i => j loop iterating 0 to (N-1), i.e., N times for each i value. so, O($N^2$) 0 votes 0 votes nag.swarna commented Nov 6, 2018 reply Follow Share Can u please explain how you got it 0 votes 0 votes nag.swarna commented Nov 6, 2018 reply Follow Share Second function??? 0 votes 0 votes Naveen Kumar 3 commented Nov 6, 2018 reply Follow Share b) i loop is iterating with value, 1, 2, 4, 8, 16 , ...., $2^N$ so, O(N). 0 votes 0 votes Naveen Kumar 3 commented Nov 6, 2018 reply Follow Share @Soumya pow() is constant operation=> O(1) &, loop is iterating till 'max' => O(n) 1 votes 1 votes Dhillu Thambi commented Nov 6, 2018 reply Follow Share Ans. D a) O(n2) b) for loop : O(logN) depends on the implementation of pow() function, the complexity changes. It can be O(n) or O(log N). So the only option that makes sense is the D 0 votes 0 votes Shaik Masthan commented Nov 6, 2018 reply Follow Share For second program, for(i=0;i<K;i=i*2) ====> O(log2K) in the place of K, we have 2n ===> O(n) depends on the implementation of pow() function they didn't mention about it, ===> take it as O(1) 0 votes 0 votes Mayankprakash commented Nov 6, 2018 reply Follow Share @naveen Kumar 3 How 1,2,4,8......2^n leads to O(N)? @shaik for(i=0;i<K;i=i*2) ====> O(log2K) in the place of K, we have 2n ===> O(n) In above 2 points,if it's k in loop it's O(LOGK) and how if 2^n then it's O(N)? 0 votes 0 votes Shaik Masthan commented Nov 6, 2018 reply Follow Share if it's k in loop it's O(LOGK) and how if 2^n then it's O(N)? O( log2K) = O( log2(2N)) = O(N) 0 votes 0 votes Naveen Kumar 3 commented Nov 6, 2018 reply Follow Share How 1,2,4,8......2^n leads to O(N)? $2^0$ , $2^1$ , $2^2$ , $2^3$ ,..., $2^N$ ===> N terms. 0 votes 0 votes Subarna Das commented Nov 6, 2018 reply Follow Share @ nag.swarna If you're adding a test-series question, you've to specify the name of the test-series from where you took this qs. 0 votes 0 votes Mayankprakash commented Nov 6, 2018 reply Follow Share Thanks Naveen 0 votes 0 votes Please log in or register to add a comment.