algorithm - Determining the big-O runtimes of loop with inner loop repeat time is const -
i have function
for(int i=0;i<n; i++) { b[i]=0; for(int j=0;j<5;j++) { b[i]=a[j+i] } }
i need calculate big-o of above function. answers is:
inner loop run 5n
time => o(n)
. total complexity o(n)
. think have mistake in calculations, don't know mistake.
no, haven't made mistake. correct in thinking , solution perfect!
the outer-loop run n-times , inner loop runs 5(constant) times.
therefore, loops complexity o(5*n) = o(n) , other statements of constant time-complexity.
since, 5*n times execution of program means o(n) time-complexity of program.
Comments
Post a Comment