(Java) For the following code segment, match the different values of the empty line with the resulting Big O complexity of the algorithm.
int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { // ___MISSING CODE___ k++; } }
j = 0;
j--;
j /= 2;
j = j * 2;
Options for each are: O(n^3) O(n * log n) an infinite loop results O(1) O(n^2) O(n)
int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { j = 0; k++; } } Time complexity = O(n) int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { j--; k++; } } Time complexity = O(n^2) int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { j /= 2; k++; } } Time complexity = O(n * log(n)) int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { j = j * 2; k++; } } Answer: an infinite loop results
Get Answers For Free
Most questions answered within 1 hours.