Defining a recursive function $f$ on $\{a, b\}$*

52 Views Asked by At

I would need some help on how I can define a recursive function $f$ on $\{a, b\}$*

Define a recursive function $f$ on $\{a, b\}$* which replaces any $a$ with $b$ and vice versa, for example, $f(aba) = bab$ and $f(aaabbb) = bbbaaa$

I would appreciate hints and/or examples or atleast how I need to think to solve a task like this one.

Thank YOU.

1

There are 1 best solutions below

16
On BEST ANSWER

HINT: It’s actually more similar than you might think to this question. If $w\in\{a,b\}^*$, and you know what $f(w)$ is, what are $f(wa)$ and $f(wb)$ in terms of $f(w)$?