Help with my big oh algorithm analaysis

  • Thread starter Thread starter mycrafish
  • Start date Start date
  • Tags Tags
    Algorithm
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
mycrafish
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if (i == j){
for(int k = 0; k < n*n; k++){
System.out.println();
}
}
else{
for(int h = 1; h <= n; h = h*2){
System.out.println();
}
}
}​
 
Physics news on Phys.org
Any attempt at a solution? Where have you gotten so far? As a small hint, O(n) is the worst case, so look at those loops and think where the most steps can be taken.
 
i know the answer is n3 + n2log2n - nlog2n but i have no idea how to get this far
I know the loops runs n^2 times at least but I am not sure how to do the if statements