### Preview lessons, content and tests

#### Computer Science & Programming solved. All in one platform.

1. To trial the platform and take tests, please take a few seconds to SIGN UP and SET UP FREE.

2. Searching for something specific? See our text overview of all tests. Scroll right for levels, and lists.

3. Student and Teacher User Guides |  Schemes of Work |   Real Teacher use Videos |

Join 36000+ teachers and students using TTIO.

### Recursion

In computer science, recursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. Such problems can generally be solved by iteration, but this needs to identify and index the smaller instances at programming time. Recursion solves such recursive problems by using functions that call themselves from within their own code.

### PowerPoint Presentation

Examples given in VB.Net - use as pseudocode and convert into your language of choice.

### Suggested Video - Python and Recursion

Think of recursion like a magic superpower that allows you to solve problems easily!

The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

"The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions."

Niklaus Wirth, Algorithms + Data Structures = Programs, 1976

Most computer programming languages support recursion by allowing a function to call itself from within its own code.

### Two useful links - practice problems

https://realpython.com/python-thinking-recursively/

https://www.w3resource.com/python-exercises/data-structures-and-algorithms/python-recursion.php

In order to be successfully recursive a recursive function must obey 3 rules:

3 Rules of recursion

• The algorithm must have a base case
• The algorithm must work towards the base case
• The algorithm must call itself recursively

Why use recursion?

Recursion is useful in many problems where iteration would prove difficult or impossible.

Stacks and Unwinding

Unwinding is the process of returning from one stack from back down to the next, and so on until recursion is complete.

### Interactive (Game) Example - Try it yourself

https://learnlearn.uk/alevelcs/recursive-maze-solving-algorithm-tutorial/

www.teachyourselfpython.com