forked from dbc2201/AlgorithmicComplexities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigO_n.java
31 lines (29 loc) · 857 Bytes
/
BigO_n.java
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
29
30
31
/*
* Created by IntelliJ IDEA.
* User: divyanshb
* Date: 14/01/20
* Time: 8:27 AM
*/
package examples;
/**
* This class will show an example for an algorithm that has a time complexity of
* O(n) - Big Oh of n.
*/
public class BigO_n {
/**
* This method "traverses" the input {@param array} and then prints all the values.
*
* @param array the input array to print
*/
public static void printArray(int[] array) {
/*
* This for loop will run as many times as the length of the array.
* So, if we suppose that the length of the array is 'n', then the loop
* will also run 'n' times.
* Hence, the complexity O(n)
* */
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + (i < array.length - 1 ? ", " : ""));
}
}
}