0

I'm trying to see if I got these running times right, are these running times for these algorithms correct.

Algorithm 1:

x=0
for  i=1 to n
   for  j=1 to i
      if( i+j > n) return; //so whenever i+j first reaches n, the algorithm stops

Running time I got: O(n)?

Algorithm 2:

x=0
for  i=1 to n
   for  j=1 to n
      x++

 for i=1 to  n^2
    for  j=1 to i
      x++;

Running time: O(n^4)? I think this one is wrong? Please help

x=101 [in binary]
for  i=1 to n   
   x = ADD(x,x)   [in binary]

Running time: O(n)?

0 Answers0