-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBigO_nPolynomial.java
More file actions
28 lines (25 loc) · 843 Bytes
/
BigO_nPolynomial.java
File metadata and controls
28 lines (25 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Created by IntelliJ IDEA.
* User: divyanshb
* Date: 14/01/20
* Time: 8:36 AM
*/
package examples;
public class BigO_nPolynomial {
private static int[][] twoDimensionalArray = new int[3][3];
/**
* As we can see, both the loops run n times, hence both of them have a
* complexity of O(n), so when we multiply these complexities together we get,
* O(n x n) OR O(n^2).
* It would be true for any number of nested loops, if we add another loop inside
* the 'j' loop that also runs 'n' times, then the total complexity of this
* algorithm would be O(n^3)
*/
public static void printTwoDimensionalArray() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.println(twoDimensionalArray[i][j]);
}
}
}
}