Calculate the time complexity of an algorithm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orestismaths
    New Member
    • Jan 2010
    • 1

    Calculate the time complexity of an algorithm

    Can you please explain to me what is the execution time T(n) of the 3 algorithms?

    Algorithm 1:

    y ← 0
    j ← n
    while j >= 1 do {
    k ← 0
    while k < n*n do {
    y ← y + j - k
    k ← k + 1
    }
    j ← j - 1
    }
    return y

    Algorithm 2:

    for i ← 1 to n do
    for j ← 1 to i do
    for k ← j to i+j do
    a ← a + 1
    end for
    end for
    end for


    Algorithm 3:

    for i ← 1 to m do
    for j ← 1 to i2 do
    for k ← 1 to j do
    b ← b + 1
    end for
    end for
    end for
  • shabinesh
    New Member
    • Jan 2007
    • 61

    #2
    I think the the calculation for alogrithm 3 and 4 are similar;
    d=(n * i * (i+j) )* c assuming c is some constant value for increment operation
    I guess they should fall under O(d)

    P.S: I am not sure about it

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

      Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

      Then when you are ready post a new question in this thread.

      MODERATOR

      Comment

      Working...