performance - Big O Run Time for nested loops? -
performance - Big O Run Time for nested loops? -
how calculate big o run-time efficiency code? gut tells me o(n^3) i'm not sure, i'm not sure if loops independent or dependent.
for (i=1; i<=n; i++) (j=1; j<=n; j++) (k=1; k<=n; k++) print ("%d %d %d/n", i, j, k);
your gut feeling right. have 3 nested loops iterating on n, each of first n loops create n loops, each of in turn create n more loops. o(n^3).
edit: think how play out- first 1, j 1 well, , k loops 1 through n. after k has undergone whole loop, j increment 2, k undergoes loop 1 time 1 time again , on.
performance algorithm data-structures runtime big-o
Comments
Post a Comment