What is the time complexity for the following codes What is
What is the time complexity for the following codes
What is the time complexity of these algorithms, in terms of n? Code1 for (int i = 1 to n) {for (1nt j = I to n) {for (int k = j to n) {Sum +- a[1]*b[j]*c[k]} if (gcd(i, j) ==1) {j = n}}} Code2 j =1 while (jSolution
Code 1:-
The Time complexity of nested loops is nothing but the number of times the innermost statements are executed.
Here we have 3 for loops and every for loop will be executed n times. Therefore the total time complexity of
nested loops is equal to O(n^3).
