If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Big-Oh Notation Question

Looks to me like the inner loop wont run for the first time through the segment because count2 is equal to count. After count is incremented once that inner loop will have to run one more time every time through. So it cant just be O(n) right?

Re: Big-Oh Notation Question

Originally Posted by laserlight

If that were true
...
Clearly, your statement must be wrong.

Appreciate the help but I figured it out just looking at the patterns of the code and determined the outer loop is O(N) and that the inner loop just performs 2^n like I said earlier, which in log base 2 is just logN.

Since the while loop is inside of outer loop I multiplied O(N) by O(logN) giving me O(NlogN)

Re: Big-Oh Notation Question

sorry, it's still wrong. Again, count the number of times the inner loop cycles ( no, it's not 1 nor 2^n. try following the code as it runs, eventually with a debugger or just with pen and paper ).

You know what, I really dont care...I worked on this for a huge chunk of yesterday and it was only a tiny fraction of my assignment. Not only that I was trying to be nice saying I appreciate the help, but what help have you given? Day and a half later and still not even a single post on what direction I should take other than "how many times was count = count * 2 invoked. I've asked multiple people who know how to find big-oh and they all agree its nlogn.

Re: [RESOLVED] Big-Oh Notation Question

Originally Posted by quixomatic

the inner loop just performs 2^n like I said earlier, which in log base 2 is just logN.

You did not say that. Rather, you asked if "the complexity of the inner loop is O(2^n)". It isn't, as you yourself have now concluded. What you probably have in mind is the idea that the value of count2 increases at a rate proportional to 2^n. Thus, the number of iterations of the inner loop is proportional to log n.

Originally Posted by quixomatic

Since the while loop is inside of outer loop I multiplied O(N) by O(logN) giving me O(NlogN)

Yes, that is correct

EDIT:

Originally Posted by quixomatic

Day and a half later and still not even a single post on what direction I should take other than "how many times was count = count * 2 invoked.

The thing is, figuring that out is the key to figuring out the complexity of the inner loop, and is likely to be the core lesson of this exercise. Once you know the complexity of the inner loop, the overall complexity of the code snippet is obvious since the outer loop's complexity is obvious.

Re: [RESOLVED] Big-Oh Notation Question

Appreciate the response Laserlight, I admit I did not have an strong understanding of what complexity is or how to find it, but when I said it performs 2^n I did mean that the inner function itself was computing exactly that. I may have reached my answer differently, but never once did superbonzo say I was getting closer or that I had the right idea.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.