You are not logged in. Please login at www.codechef.com to post your questions!

×

# time complexity of a loop with conditions in it !!

 0 hi all...im using a nested loop in which i go into second loop if and only if it pass through a condition else do nothing...similarly the same in d second loop....if i run my both loops from i=1 to i=n what would be d time complexity ?? asked 06 Sep '17, 17:10 1★msd_007 317●8 accept rate: 5%

 0 Depends. It can be anything from $O(NLog(LogN))$ to $O({N}^{2})$. It depends on condition and value of increment. Sieve of erastothenes is nested loop, but it runs in $O(NLog(LogN))$ (due to increasing increment after every iteration+Decreasing chances of condition being true). But on the other hand, any thing like "If number is even then run from i=1 to N, incrementing i by 1" will be clearly $O({N}^{2})$. answered 06 Sep '17, 19:04 15.4k●1●20●66 accept rate: 18%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×204
×83

question asked: 06 Sep '17, 17:10

question was seen: 389 times

last updated: 06 Sep '17, 19:05