-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
  • 73,212
  • 30
  • 182
  • 400

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