997 views
1 votes
1 votes

for (int i = 1; i <=m; i += c)

{  ---do something ---}

for (int i = 1; i <=n; i += c)

{ ---do something ---  }

What will the the tiem complexity of given code pseudococde?

A. O (max(m,n))

B. O(min(m,n))

C. O( m+n)

D. O(mn)

2 Answers

Best answer
6 votes
6 votes

we generally give complexity according to the inputs given to that algorithm, here the inputs are both m,n ...so both m,n defines the complexity and they must be included in the complexity expression, as there is no relationship between m and n are mentioned in the ques ... so ans is C

http://www.geeksforgeeks.org/analysis-of-algorithms-set-4-analysis-of-loops/

selected by

Related questions

1 votes
1 votes
1 answer
1
radha gogia asked Jul 31, 2015
1,080 views
what is the approach of this question , Is it that first we will traverse all the pairs then find the minimum distance between all the pairs
2 votes
2 votes
3 answers
2
Meenakshi Sharma asked Sep 4, 2016
1,909 views
For(I=1 ; I<=n ; I++) { For(J=1 ; J<=I ; J++) { For(K=1 ; K<=n^5 ; K=15 × K) { x=y+z; } } }What is the time complexity of above code ?
0 votes
0 votes
1 answer
3
0 votes
0 votes
2 answers
4
omveer asked Sep 5, 2016
476 views
While(n>1){n=n/20;n=n/10;}Find time complexity.