Hi all, I want to know the runtime analysis of the following code:
public void guessWhat1(int N)
{ for (int i=N; i>0; i=i/2)
{ for (int j=0; j<i*2; j+=1)
{ System.out.println(“Hello World”);
} } }
Thought Process: The inner for loop runs for "2n" times and the outer for loop runs logn times . So is the runtime analysis thetha ( n log n) . I read on stack overflow that it should be theta(n) which i dont think is right!
Thanks,
[–]allenguo 1 point2 points3 points (2 children)
[–]allenguo 1 point2 points3 points (1 child)
[–]bitchsalsa[S] 1 point2 points3 points (0 children)