In the field of computer science, it is very important that computer scientists know how to calculate the running time of algorithms to optimize code. For you computer scientists, I ask a question.
I understand that in terms of n, a double nested for-loop usually has a run time of n 2 and a triple nested for-loop usually has a run time of n 3 .
However, for the case where the code looks like this, will the runtime be n4?
x = 0; for(a = 0; a < n; a++) for(b = 0; b < 2a; b++) for (c=0; c < b*b; c++) x++;
I simplified the run time for each row to be practically (n + 1) for the first cycle, (2n + 1) for the second cycle, and (2n) 2 +1 for the third cycle. Assuming the members are multiplied together and we extract the highest term to search for Big Oh, whether the run time is n 4 or will it still follow the normal time n 3
I would be grateful for any input. Thank you so much in advance.
source share