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)?

  • We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – D.W. Oct 06 '15 at 04:52
  • All three of your self-answers are correct. – Rick Decker Oct 06 '15 at 20:40

0 Answers0