Recursion via Pascal
http://www.retroprogramming.com/2011/01/recursion-via-pascal.html
Recursion via Pascal by J. S. Rohl is one of a small number of books devoted entirely to recursion in programming.
(
8 comments
| 8 points
| on HN
)
This is the one place where "pure" functional languages have such potential. If the function is guaranteed side-effect free then the calls can be memo-ised, and this routine becomes O(lg n) "for free".
Now call it with n=4. Time taken is 2T(2) plus a multiply. Hence T(4)=2(2c+m)+m=4c+3m.
Inductively we can prove that T(n)=n * c + m, where c is the time of a call, and m is the time of a multiply, and I'm ignoring small details.
If you save the result of a call and reuse it then you get a different result, of course, and if you really want to learn how this works then you should try to figure it out.
MyArray: array[1..10] of Byte;
or if you want something that can be used as a buffer:
MyCharArray: array[0..19] of Char;
StrCopy(@MyCharArray,'Hello World'); // array acting like a 0-indexed Char buffer
Do you mean strings?