I’m looking for a few recursive function examples, preferably ones that show increase in complexity. I understand basic recursive functions, but I’m having trouble implementing them in my code. I’ve never used them in my code before, and I know it doesn’t always call for it, but I’d like to try. Is there a good resource with examples, and maybe challenges of some sort? Or even some simple math problems (Project Euler-style?) that I could use recursion on?
For examples, I prefer C#, but anything works.
1 the easiest ones are factorial, Fibonacci sequences, or any mathematical sequence defined by recursive functions.
2 then you can move to
any algorithms that use a depth first search.
E.g. tree traversal, graph traversal,
search problems, like 8-queens problems.
3 you’d probably like to study
divide and conquer algorithm, e.g. merge sort and quick sort. they are usually implemented recursively.
These are all very classical!