-1

The following is pseudo code and I need to turn it into a a recurrence relation that would possibly have either an arithmetic, geometric or harmonic series.

Pseudo code is below.

enter image description here

I have so far T(n) = T(n-5) + c

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • 1
    what is your exact question? what are you looking for? Is it the run time complexity from recurrence relation? – Alwyn Mathew Jun 24 '16 at 04:29
  • Yes, I can solve that part hopefully I just need to extract the equation from that pseudo code. – user5428151 Jun 24 '16 at 04:30
  • Welcome to [cs.SE]! Note that you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction. – Evil Jun 24 '16 at 04:48
  • So far I have $$T(n) = T(n-5) + \sum_{i=1}^{n} c$$ – user5428151 Jun 24 '16 at 04:54
  • 2
    Don't use images as main content of your post. This makes your question impossible to search and inaccessible to the visually impaired; we don't like that. Please transcribe text and mathematics (note that you can use LaTeX) and don't forget to give proper attribution to your sources! Please edit your question instead of posting comments. – Evil Jun 24 '16 at 05:27
  • 2
    http://cs.stackexchange.com/q/23593/755 – D.W. Jun 24 '16 at 05:27

1 Answers1

1

T(n) = T(n-5) + c

Solution by substitution:

$T(n) = T(n-5) + c..................................(1)$

therefore, $T(n-5) = T(n-10) + c ....................(2)$

Substituting $(2)$ in $(1)$, gives

$T(n) = T(n-10) + c + c .............................(3)$

Similarly, $T(n-10) = T(n-15) + c ....................(4)$

Substituting $(4)$ in $(3)$, gives

$T(n) = T(n-15) + c + c + c .........................(5)$

and so on.

Finally, $T(n) = T(k) + \frac{cn}{5}$ where $k<=4$

then $T(n) = 1 + \frac{cn}{5}$

therefore $f(n)=O(n)$ as $\frac{c}{5}$ is a constant.

Alwyn Mathew
  • 551
  • 2
  • 13
  • Thank you for this, but this is all assuming that T(n) = T(n-5) + C I am not sure that is the proper equation from the pseudo code. – user5428151 Jun 24 '16 at 05:21