0
static int bar(int[] z) {
int x = z.length;
for (int i = 0; i < x/2; i++) {
   for (int j = 0; j < x; j += 3) {
     if (z[i] == 10) {
        System.out.println("Hi");
        break;
     }
    }
    for (int k = 0; k < x; k++) {
       System.out.println("Lo");
       if (k >= i) break;
     }
  }
}

I am having difficulty trying to understand how this program would be O(n^2).

I have been trying to represent this in sigma notation like: (https://i.stack.imgur.com/mbSK7.png) I am not sure how the second nested for loop would play into what I have already. What do I need to understand in order to complete the equation I made?

cool
  • 1

0 Answers0