I need some help on solving a recursive function question

75 Views Asked by At

I'm working on a recursive function task which i'm a bit stuck at. I've tried to google it on how I can solve this task, but with no luck

Here is the task:

Provide a recursive function $r$ on $A$* which gives the number of characters in the string

I Hope I can get some help here, since i've tried nearly everything.

Thanks alot for your kind help!

2

There are 2 best solutions below

0
On

This seems rather a programing question than a mathematical one, but the idea of recursiveness would be something like:

  1. if the string is empty, answer 0
  2. otherwise, answer is 1 + the lenght of the substring after second position

This recursiveness only make sense in implementations such as C's $0$-terminated strings.

3
On

Kindly see if this helps you.

r = f(A)

f(A) = 0 if f(A) = ∅

 = 1 + f(A-{c}) otherwise

where {c} is the character extracted from the string.