-2
for i <--- 1 step i <--- 2* i while i< n do 
  for j <--- 1 step j <---2* j while j<n do 
    if j = 2*i 
      for k = 0 step k <--- k+ 1 while k < n do 
        .... CONSTANT NUMBER OF ELEMENTARY OPERATIONS 
      end for 
    else 
      for k<--- 1 step k<-- 3*k while k<n do 
        ...CONSTANT NUBER OF ELEMENTARY OPERATIONS 
      end for 
    end if 
  end for 
end for

What is the running time for the following code fragment as a function of n?

The 'exact answer' refers to the equation relating to the code BEFORE you determine the asymptotic running time.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Ice
  • 3
  • 4

1 Answers1

0

It sounds as homework, however, making a few considerations, the asymptotic complexity of that pseudo code should be O(n*log(n)).

You cannot estimate exactly the running time since it highly depends on your system.

Manlio
  • 10,768
  • 9
  • 50
  • 79
  • Its not homework. Its an exercise from a book. I get a different answer thats why. The book has no answers so I dont know how to double check myself. I actually got a different answer and cheers for that. I will practise more these but sometimes I getconfused between asymptotic and exact answer. Would you be kind enough to explain the difference. – Ice Aug 06 '11 at 23:08