Do "if" statements affect in the time complexity analysis?
Posted
by
FranXh
on Stack Overflow
See other posts from Stack Overflow
or by FranXh
Published on 2012-09-01T21:19:21Z
Indexed on
2012/09/01
21:38 UTC
Read the original article
Hit count: 202
According to my analysis, the running time of this algorithm should be N2, because each of the loops goes once through all the elements. I am not sure whether the presence of the if
statement changes the time complexity?
for(int i=0; i<N; i++){
for(int j=1; j<N; j++){
System.out.println("Yayyyy");
if(i<=j){
System.out.println("Yayyy not");
}
}
}
© Stack Overflow or respective owner