Question: Compute for the space complexity, total cost ( show the process) and determine the time complexity (Big O notation). JAVA public class Program { public
Compute for the space complexity, total cost ( show the process) and determine the time complexity (Big O notation).
JAVA
public class Program { public static void main(String[] args) { int[] array1 = { 10, 20, 30 }; int[] array2 = { 20, 10, 30 }; int[] array3 = { 40, 40, 10 }; long t1 = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++) { int sum = 0; for (int x = 0; x < array1.length; x++) { sum += array1[x]; }
for (int y = 0; y < array2.length; y++) { sum += array2[y]; }
for (int z = 0; z < array3.length; z++) { sum += array3[z]; } if (sum != 210) { System.out.println(false); } }
long t2 = System.currentTimeMillis(); for (int b = 0; b < 10000000; b++) { int add = 0; for (int c = 0; c < array1.length; c++) { sum += array1[c]; sum += array2[c]; sum += array3[c]; } if (sum != 210) { System.out.println(false); } }
long t3 = System.currentTimeMillis(); / System.out.println(t2 - t1); System.out.println(t3 - t2); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
