What is the complexity class of the following algorithm and why?
1 replies, posted
[code]int m = -9
for (j = 0; j < n; j+=5)
{
if (j<m)
{
for (k = 1; k <n; k*=3)
{some code}
}
}[/code]
I'd say it's O(n) because we never enter the second loop and we aren't really concerned with O(n/5) i.e. we simplify/approximate.
[url]http://facepunch.com/showthread.php?t=1250528[/url]
[editline]23rd May 2013[/editline]
But yeah, O(n), even if n is -1 and j loops all the way back around, it's never going to be -9.
Sorry, you need to Log In to post a reply to this thread.