terminal

codeando_simple

terminal

menu

terminal

search_module

guest@codeandosimple: ~/system/search $ grep -r "" .

Press [ENTER] to execute search

Status

Engine: Ready

Database: Online

Index: V2.1.0_LATEST

bash -- cat logica-recursividad.md
guest@codeandosimple: ~/blog/logic $ cat recursion.md

Logic - Recursion_

// "The Sum of Small Daily Progress Causes Great Results" - Satya Nani

Recursion is a technique where a function calls itself. It is usually used to replace repetitive structures in problems of a recursive nature, creating short and elegant algorithms.

Video thumbnail

# Calling itself

A recursive function contains a call to itself within its body. It is vital to establish a stop condition (base case) to avoid infinite executions.

Recursive scheme
Recursive cycle

# Exercise: The Factorial

The factorial of a number N is defined as N * Factorial(N-1). The base case is Factorial(0) = 1.

Recursive factorial code

Graphical process (3!)

Factorial stack tracing

# Exercise: Fibonacci

Sequence: 1, 1, 2, 3, 5, 8, 13... The function is based on adding the two previous terms.

Recursive Fibonacci code

Summary

Recursion allows for elegant and short algorithms. Although it consumes more memory due to stack management, it is fundamental for navigating structures like trees and graphs.

In the next article, we will see flowcharts, a tool to visualize algorithms.

Resources used