Are you guys sure about that runtime?
The first loop runs n times. And for each n, it runs 2^n. Thus the total runtime is O(n*2^n)
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
>>Summation of 2^i + 1 from i = 0 to n-2.
That shows right there that its O(n*2^n);
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
@CSurfer
What is the runtime of this :
for i = 0 to N - 1
for j = 0 to N - 1
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
@firstPerson:
Its BigOh(N^2)
Just to see what you are thinking, can you explain how you got that in terms of summation, as you did in your proof couple of post ago. I just want to see exactly where we differ and see if I am wrong or if you are wrong.
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
Ok and the code OP showed should be similarly proved right? Like so :
Summation from i = 1 to N
Summation from j = x, where x = 2^i
Thus N * Summation from j = x, where x = 2^i = {1,2,4,8,16...}
If you look on wiki_summation. In the growth rate section it tells you that: Summation from i to N of c^i = THETA(c^n).
In our case c = 2, thus Summation from i to N of 2^i = THETA(2^n);
Thus N * Summation from j = x, where x = 2^i
= N * THETA(2^n)
= THETA(n*2^n)
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15