View Single Post
  #1 (permalink)  
Old 09-07-2008, 09:25 PM
Pillager Pillager is offline
Newbie
 
Join Date: Sep 2008
Posts: 1
Credits: 0
Rep Power: 0
Pillager is on a distinguished road
Default Homework help - Algorithm complexity

Hi guys, I was wondering if anyone could give me any tips on these exercises I am trying.

I'm trying to make an algorithm that runs proportional to O(log(nē)).

The attempt I've coded (in java) looks something like this:

Code:
int count = 0;

for(int i=1; i<n; i*=2) {

  for(int j=0; j<n; j++) {

    for(int k=0; k<n; k++) {

     count++; }}}

Now from my understanding I thought that the two inner loops would give an Nē complexity, which would then be multiplied by the outer loop which has a log complexity. I assume something fairly fundamental is tripping me up, I suspect either the order of my loops or a math error based on the log part.

Anyway thanks for any advice you can give, feel free to give any general tips on algorithm analysis if you want as I think I only have a vague grasp on the topic.
Reply With Quote

Sponsored Links