big o - Asymptotic analysis: Python Big-O homework -


i have homework question asks me give tight big-o estimate of worst-case time-complexity of following python code:

sum = 0 = n while > 1:     k in range(n*n):         sum = sum + k*i     = // 2 

the outer loop seem have o(log n) time-complexity because of line = // 2. inner loop appears have o(n^2) time-complexity because range n*n. 2 loops seem independent of each other overall time-complexity o(n^2)?

you may think of complexity number of simple operations needed complete given task. outer loop says perform given operation log(n) times correctly point out in question. these operations not simple - consist of performing cycle. cycle performs o(n^2) simple operations as, again, point out correctly. try think total number of simple operations performed code fragment?

note: in answer assume addition , integral division simple operations.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -