cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
time complexity
time complexity
Apr 3, 2015 at 10:15pm UTC
SaifN
(1)
Hi,
Can you help me figure out time complicity of this code:
func(n)
s←0;
for i←n to n^3
do
j←1;
while j < i^2
do
j←j×2;
s←s+j−i;
return(s);
thanks
Apr 4, 2015 at 7:42am UTC
Smac89
(1727)
Outer loop runs n
3
times. Each iteration of outer loop results in i
2
iterations of inner loop. So the number of times they run in total is the sum 1
2
-> n
3
^2
Formula to get this sum:
http://www.trans4mind.com/personal_development/mathematics/series/sumNaturalSquares.htm
Topic archived. No new replies allowed.