-1

How do I determine the running time (in terms of Big-Theta) for the algorithm of input size n that satisfies recurrence relation T(n) = T(n-1)+n where n >= 1 and with initial condition T(1) = 1?

Edit: I was practicing a past exam paper. Got stuck on this question. Need guidance

Eninfo
  • 217
  • 1
  • 2
  • 11
  • 1
    No this is not a homework question. This is one of the questions in the past exam paper that I was given to practice as a preparation for an exam in future. I was just stuck on this question. – Eninfo Nov 05 '15 at 09:31

1 Answers1

1

Look at it this way: T(n) = T(n-1) + n = T(n-2) + (n-1) + n = T(n-3) + (n-2) + (n-1) + n. Which means if n >= 1 then you will get something like T(n) = 1 + 2 + 3 + ... + n. If you work out the pattern of this series you will see that (n+1)n/2. Therefore, Ө(n^2)

Akrytek
  • 26
  • 2