Ahmed Belhaj
2 min readFeb 1, 2021

A Picture is Worth 1,500 Words (concept of recursion)

Recursion Colorized

Introduction

Recursion means “defining a problem in terms of itself”. This can be a very powerful tool in writing algorithms. Recursion comes directly from Mathematics, where there are many examples of expressions written in terms of themselves.

For example, we can define the operation “find your way home” as:

  1. If you are at home, stop moving.
  2. Take one step toward home.
  3. “find your way home”.

The solution to finding a way home is three steps . First we don’t go home if we already there , Second we make a step that make the way simpler , Third one is redo the entire thing until we reach the first step .

Parts of a Recursive Algorithm

All recursive algorithms must have the following:

  1. Base Case (condition of stop)
  2. Work toward Base Case
  3. Recursive Call (call ourselves)

Example of pow recursive :

Example of function

Recursion in stack

Example of what happen in stack
Ahmed Belhaj
Ahmed Belhaj

Written by Ahmed Belhaj

Dedicated DevOps Engineer with expertise in system administration, core development, and a full-stack software development.

No responses yet