SlideShare une entreprise Scribd logo
1  sur  68
UTN FRLP
Ing. en Sistemas de información
Concurso docente
Sintaxis y Semántica del Lenguaje
2014
Ing. Julián Perelli
TEMARIO
Técnicas de recursión
Introduccion – Ejemplos de uso
Definición
Ejemplos de programación
Backtracking
Recursión vs iteración
Utilidad de la recursión
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 2/68
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 3/68
Problemas de naturaleza recursiva
Parsing matemático: calculadora con paréntesis
2 × (a −1) + (3 × b)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 4/68
Problemas de naturaleza recursiva
Ordenamiento: Quicksort / Merge sort
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 5/68
Problemas de naturaleza recursiva
Camino mas corto (dijkstra)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 6/68
Problemas de naturaleza recursiva
Fractales
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 7/68
Problemas de naturaleza recursiva
Fractales
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 8/68
●
Algoritmo
●
Estructura condicional (if)
●
Función
●
Pila de ejecución (Stack)
CONOCIMIENTOS REQUERIDOS
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 9/68
¿Qué es la recursión?
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 10/68
Frase popular
Para saber qué es la recursión
primero hay que saber
¿QUÉ ES LA RECURSIÓN?
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 11/68
Frase popular
Para saber qué es la recursión
primero hay que saber
qué es la recursión.
¿QUÉ ES LA RECURSIÓN?
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 12/68
Algoritmo recursivo:
un algoritmo que depende de la ejecución
repetida de sí mismo.
¿QUÉ ES LA RECURSIÓN, REALMENTE?
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 13/68
Algoritmo recursivo:
un algoritmo que depende de la ejecución
repetida de sí mismo.
¿QUÉ ES LA RECURSIÓN, REALMENTE?
?
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 14/68
Algoritmo recursivo:
Function recursionInfinita();
Begin
recursionInfinita()
end
¿QUÉ ES LA RECURSIÓN, REALMENTE?
∞
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 15/68
Algoritmo recursivo:
un algoritmo que depende de la ejecución repetida
de sí mismo.
Function recursionInfinita()
Begin
recursionInfinita();
end
recursionInfinita()
¿QUÉ ES LA RECURSIÓN, REALMENTE?
Function recursionInfinita()
Begin
recursionInfinita();
end
Function recursionInfinita()
Begin
recursionInfinita();
end
Function recursionInfinita()
Begin
recursionInfinita();
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 16/68
Hacer un procedimiento recursivo que muestre
por pantalla un número dado “n”.
EJERCICIO 1
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 17/68
Hacer un procedimiento recursivo que muestre
por pantalla un número dado “n”.
Procedure contar(n: Integer);
Begin
WriteLn(n);
contar(n);
End
EJERCICIO 1
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 18/68
Hacer un procedimiento recursivo que muestre
por pantalla un número dado “n”.
Procedure contar(n: Integer);
Begin
WriteLn(n);
contar(n);
End
EJERCICIO 1
Llamada recursiva
contar(5)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 19/68
Hacer un procedimiento recursivo que muestre
por pantalla un número dado “n”.
Procedure contar(n: Integer);
Begin
WriteLn(n);
contar(n);
End
EJERCICIO 1
Llamada recursiva
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 19/68
Function contar(n = 5)
Begin
WriteLn(n = 5);
contar(n = 5)
end
contar(5)Function contar(n = 5)
Begin
WriteLn(n = 5);
contar(n = 5)
end
contar(5)Function contar(n = 5)
Begin
WriteLn(n = 5);
contar(n = 5)
end
contar(5)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 20/68
Cada llamada ocupa memoria que nunca se libera,
porque ningún procedimiento termina.
Computación limitada por tamaño de memoria.
Se genera un desbordamiento de pila.
¡ESTO NO SIRVE!
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 21/68
1. Llamada recursiva (por definición).
2. Condición de corte.
3. Cada llamada recursiva converge (se acerca)
paso a paso a la condición de corte.
ALGORITMO RECURSIVO ÚTIL
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 22/68
Hacer un procedimiento recursivo que muestre por
pantalla todos los números naturales que existen desde
un número dado “n” hasta 100.
EJERCICIO 2
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 23/68
Hacer un procedimiento recursivo que muestre por pantalla
todos los números naturales que existen desde un número dado
“n” hasta 100.
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
EJERCICIO 2
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 24/68
EJERCICIO 2
1. Llamada recursiva
3. Acercamiento a la condición de corte
2. Condición de corte
Hacer un procedimiento recursivo que muestre por pantalla
todos los números naturales que existen entre un número dado
“n” hasta 100.
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 25/68
EJERCICIO 2
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
contar(98)
Impresión
(registro de activación)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 26/68
EJERCICIO 2
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
contar(98)
98
Impresión
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 27/68
EJERCICIO 2
contar(98)
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
Impresión
98
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 28/68
EJERCICIO 2
contar(98)
98 < 100 (true)
Impresión
98
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 29/68
EJERCICIO 2
contar(98)
contar(98 +1)
Impresión
98
99
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 30/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
Impresión
98
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 31/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
99
Impresión
98
99
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 32/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
99 < 100 (true)
Impresión
98
99
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 33/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
contar(99 +1)
Impresión
98
99
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 34/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
contar(100)
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
100
99
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 35/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
contar(100)
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
99
100 < 100 (false)
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 36/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98
contar(100)
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
99
100 < 100 (false)
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 37/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98 99
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 38/68
EJERCICIO 2
contar(98)
contar(99)
procedure contar(n: intege
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
98 99
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 39/68
EJERCICIO 2
contar(98)
98
Impresión
98
99
100
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 40/68
EJERCICIO 2
contar(98)
98
Impresión
98
99
100
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 41/68
EJERCICIO 2
contar(98)
Impresión
98
99
100
Hacer un procedimiento recursivo que muestre por pantalla
todos los números naturales que existen entre un número dado
“n” hasta 100 en orden inverso.
procedure contar(n: integer);
begin
WriteLn(n);
if n < 100 then
begin
contar(n+1);
end
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 42/68
EJERCICIO 2b
2° recursión
1° impresión, proceso, acción
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 43/68
EJERCICIO 2b
1° recursión
2° impresión, proceso, acción
Hacer un procedimiento recursivo que muestre por pantalla
todos los números naturales que existen entre un número dado
“n” hasta 100 en orden inverso.
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 44/68
EJERCICIO 2b
1° recursión
2° impresión, proceso, acción
Hacer un procedimiento recursivo que muestre por pantalla
todos los números naturales que existen entre un número dado
“n” hasta 100 en orden inverso.
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
Backtracking
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 45/68
EJERCICIO 2b
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(98)
Impresión
(registro de activación)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 46/68
EJERCICIO 2b
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(98)
Impresión
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 47/68
EJERCICIO 2b
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(98)
Impresión
98 < 100 (true)
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 48/68
EJERCICIO 2b
contar(98)
Impresión
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(98 +1)
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 49/68
EJERCICIO 2b
contar(98)
Impresión
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 50/68
EJERCICIO 2b
contar(98)
Impresión
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
99 < 100 (true)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 51/68
EJERCICIO 2b
contar(98)
Impresión
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
contar(99+1)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 52/68
EJERCICIO 2b
contar(98)
Impresión
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(100)
100
100 < 100 (false)
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 53/68
EJERCICIO 2b
contar(98)
Impresión
100
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(100)
100
100
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 54/68
EJERCICIO 2b
contar(98)
Impresión
100
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(100)
100
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 55/68
EJERCICIO 2b
contar(98)
Impresión
100
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 56/68
EJERCICIO 2b
contar(98)
Impresión
100
99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
99
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 57/68
EJERCICIO 2b
contar(98)
Impresión
100
99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
contar(99)
procedure contar(n: integer
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98 99
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 58/68
EJERCICIO 2b
contar(98)
Impresión
100
99
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 59/68
EJERCICIO 2b
contar(98)
Impresión
100
99
98
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 60/68
EJERCICIO 2b
contar(98)
Impresión
100
99
98
procedure contar(n: integer);
begin
if n < 100 then
begin
contar(n+1);
end
WriteLn(n);
end
98
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 61/68
EJERCICIO 2b
contar(98)
Impresión
100
99
98
Algoritmos
Recursivos
Vs
Algoritmos
Iterativos
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 62/68
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 63/68
Hacer un procedimiento iterativo equivalente al
ejercicio 2.
EJERCICIO 3
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 64/68
Hacer un procedimiento iterativo equivalente al
ejercicio 2.
EJERCICIO 3
Recursivo
procedure contar(n:
integer);
begin
WriteLn(n);
if n < 100 then
contar(n+1);
end
Iterativo
procedure contar(n:
integer);
begin
do
WriteLn(n);
n := n + 1;
until n >= 100
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 65/68
Hacer un procedimiento iterativo equivalente al
ejercicio 2.
EJERCICIO 3
Iterativo
procedure contar(n:
integer);
begin
do
WriteLn(n);
n := n + 1;
until n >= 100
end1. Llamada recursiva / bucle
3. Acercamiento a la condición de corte
2. Condición de corte
Recursivo
procedure contar(n:
integer);
begin
WriteLn(n);
if n < 100 then
contar(n+1);
end
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 66/68
OBSERVACIONES
Recursión lineal
- Una sola llamada recursiva.
- Puede ser reemplazada por un bucle while fácilmente.
- Sirve para recorrer estructuras lineales como arrays o
listas.
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 67/68
OBSERVACIONES: Utilidad de la recursión
Recursión binaria
- 2 llamadas recursivas dentro de cada bloque.
No se puede reemplazar por
un bucle while fácilmente
Sirve para recorrer estructuras de
árboles y grafos
Problemas de naturaleza
recursiva
UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 68/68
Recapitulación
Recursión:
Usos comunes
Definición
Definición + utilidad
Backtracking
Recursión vs while
Observaciones finales: utilidad

Contenu connexe

Plus de Julián Perelli

Cualbondi SotM latam 2018
Cualbondi SotM latam 2018Cualbondi SotM latam 2018
Cualbondi SotM latam 2018Julián Perelli
 
Cualbondi motivacion y comienzos - CNEISI 2012
Cualbondi motivacion y comienzos - CNEISI 2012Cualbondi motivacion y comienzos - CNEISI 2012
Cualbondi motivacion y comienzos - CNEISI 2012Julián Perelli
 
Docker and AWS for data science
Docker and AWS for data scienceDocker and AWS for data science
Docker and AWS for data scienceJulián Perelli
 
Presentacion drones ucrono
Presentacion drones ucronoPresentacion drones ucrono
Presentacion drones ucronoJulián Perelli
 

Plus de Julián Perelli (9)

Cualbondi SotM latam 2018
Cualbondi SotM latam 2018Cualbondi SotM latam 2018
Cualbondi SotM latam 2018
 
GDPR & EU cookies law
GDPR & EU cookies lawGDPR & EU cookies law
GDPR & EU cookies law
 
Cualbondi motivacion y comienzos - CNEISI 2012
Cualbondi motivacion y comienzos - CNEISI 2012Cualbondi motivacion y comienzos - CNEISI 2012
Cualbondi motivacion y comienzos - CNEISI 2012
 
Docker and AWS for data science
Docker and AWS for data scienceDocker and AWS for data science
Docker and AWS for data science
 
Charla mspba
Charla mspbaCharla mspba
Charla mspba
 
Presentacion drones ucrono
Presentacion drones ucronoPresentacion drones ucrono
Presentacion drones ucrono
 
Arduino presentacion
Arduino presentacionArduino presentacion
Arduino presentacion
 
Pampaseg 2015 - Drones
Pampaseg 2015 - DronesPampaseg 2015 - Drones
Pampaseg 2015 - Drones
 
SOTM 2014 - Cualbondi
SOTM 2014 - CualbondiSOTM 2014 - Cualbondi
SOTM 2014 - Cualbondi
 

Dernier

proyecto de mayo inicial 5 añitos aprender es bueno para tu niño
proyecto de mayo inicial 5 añitos aprender es bueno para tu niñoproyecto de mayo inicial 5 añitos aprender es bueno para tu niño
proyecto de mayo inicial 5 añitos aprender es bueno para tu niñotapirjackluis
 
RETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxRETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxAna Fernandez
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxjosetrinidadchavez
 
Registro Auxiliar - Primaria 2024 (1).pptx
Registro Auxiliar - Primaria  2024 (1).pptxRegistro Auxiliar - Primaria  2024 (1).pptx
Registro Auxiliar - Primaria 2024 (1).pptxFelicitasAsuncionDia
 
Caja de herramientas de inteligencia artificial para la academia y la investi...
Caja de herramientas de inteligencia artificial para la academia y la investi...Caja de herramientas de inteligencia artificial para la academia y la investi...
Caja de herramientas de inteligencia artificial para la academia y la investi...Lourdes Feria
 
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptx
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptxSEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptx
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptxYadi Campos
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosCesarFernandez937857
 
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSTEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSjlorentemartos
 
MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMarjorie Burga
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadAlejandrino Halire Ccahuana
 
Qué es la Inteligencia artificial generativa
Qué es la Inteligencia artificial generativaQué es la Inteligencia artificial generativa
Qué es la Inteligencia artificial generativaDecaunlz
 
la unidad de s sesion edussssssssssssssscacio fisca
la unidad de s sesion edussssssssssssssscacio fiscala unidad de s sesion edussssssssssssssscacio fisca
la unidad de s sesion edussssssssssssssscacio fiscaeliseo91
 
Historia y técnica del collage en el arte
Historia y técnica del collage en el arteHistoria y técnica del collage en el arte
Historia y técnica del collage en el arteRaquel Martín Contreras
 
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...JAVIER SOLIS NOYOLA
 
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdf
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdfCurso = Metodos Tecnicas y Modelos de Enseñanza.pdf
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdfFrancisco158360
 
La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...JonathanCovena1
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxzulyvero07
 
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzel CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzprofefilete
 

Dernier (20)

proyecto de mayo inicial 5 añitos aprender es bueno para tu niño
proyecto de mayo inicial 5 añitos aprender es bueno para tu niñoproyecto de mayo inicial 5 añitos aprender es bueno para tu niño
proyecto de mayo inicial 5 añitos aprender es bueno para tu niño
 
RETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxRETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docx
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
 
Registro Auxiliar - Primaria 2024 (1).pptx
Registro Auxiliar - Primaria  2024 (1).pptxRegistro Auxiliar - Primaria  2024 (1).pptx
Registro Auxiliar - Primaria 2024 (1).pptx
 
Caja de herramientas de inteligencia artificial para la academia y la investi...
Caja de herramientas de inteligencia artificial para la academia y la investi...Caja de herramientas de inteligencia artificial para la academia y la investi...
Caja de herramientas de inteligencia artificial para la academia y la investi...
 
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptx
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptxSEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptx
SEXTO SEGUNDO PERIODO EMPRENDIMIENTO.pptx
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos Básicos
 
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSTEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
 
MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grande
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdad
 
Qué es la Inteligencia artificial generativa
Qué es la Inteligencia artificial generativaQué es la Inteligencia artificial generativa
Qué es la Inteligencia artificial generativa
 
la unidad de s sesion edussssssssssssssscacio fisca
la unidad de s sesion edussssssssssssssscacio fiscala unidad de s sesion edussssssssssssssscacio fisca
la unidad de s sesion edussssssssssssssscacio fisca
 
Historia y técnica del collage en el arte
Historia y técnica del collage en el arteHistoria y técnica del collage en el arte
Historia y técnica del collage en el arte
 
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...
ACERTIJO DE LA BANDERA OLÍMPICA CON ECUACIONES DE LA CIRCUNFERENCIA. Por JAVI...
 
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdf
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdfCurso = Metodos Tecnicas y Modelos de Enseñanza.pdf
Curso = Metodos Tecnicas y Modelos de Enseñanza.pdf
 
Unidad 3 | Metodología de la Investigación
Unidad 3 | Metodología de la InvestigaciónUnidad 3 | Metodología de la Investigación
Unidad 3 | Metodología de la Investigación
 
Sesión de clase: Defendamos la verdad.pdf
Sesión de clase: Defendamos la verdad.pdfSesión de clase: Defendamos la verdad.pdf
Sesión de clase: Defendamos la verdad.pdf
 
La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
 
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyzel CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
el CTE 6 DOCENTES 2 2023-2024abcdefghijoklmnñopqrstuvwxyz
 

Clase concurso sintaxis 2014

  • 1. UTN FRLP Ing. en Sistemas de información Concurso docente Sintaxis y Semántica del Lenguaje 2014 Ing. Julián Perelli
  • 2. TEMARIO Técnicas de recursión Introduccion – Ejemplos de uso Definición Ejemplos de programación Backtracking Recursión vs iteración Utilidad de la recursión UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 2/68
  • 3. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 3/68 Problemas de naturaleza recursiva Parsing matemático: calculadora con paréntesis 2 × (a −1) + (3 × b)
  • 4. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 4/68 Problemas de naturaleza recursiva Ordenamiento: Quicksort / Merge sort
  • 5. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 5/68 Problemas de naturaleza recursiva Camino mas corto (dijkstra)
  • 6. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 6/68 Problemas de naturaleza recursiva Fractales
  • 7. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 7/68 Problemas de naturaleza recursiva Fractales
  • 8. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 8/68 ● Algoritmo ● Estructura condicional (if) ● Función ● Pila de ejecución (Stack) CONOCIMIENTOS REQUERIDOS
  • 9. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 9/68 ¿Qué es la recursión?
  • 10. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 10/68 Frase popular Para saber qué es la recursión primero hay que saber ¿QUÉ ES LA RECURSIÓN?
  • 11. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 11/68 Frase popular Para saber qué es la recursión primero hay que saber qué es la recursión. ¿QUÉ ES LA RECURSIÓN?
  • 12. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 12/68 Algoritmo recursivo: un algoritmo que depende de la ejecución repetida de sí mismo. ¿QUÉ ES LA RECURSIÓN, REALMENTE?
  • 13. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 13/68 Algoritmo recursivo: un algoritmo que depende de la ejecución repetida de sí mismo. ¿QUÉ ES LA RECURSIÓN, REALMENTE? ?
  • 14. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 14/68 Algoritmo recursivo: Function recursionInfinita(); Begin recursionInfinita() end ¿QUÉ ES LA RECURSIÓN, REALMENTE?
  • 15. ∞ UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 15/68 Algoritmo recursivo: un algoritmo que depende de la ejecución repetida de sí mismo. Function recursionInfinita() Begin recursionInfinita(); end recursionInfinita() ¿QUÉ ES LA RECURSIÓN, REALMENTE? Function recursionInfinita() Begin recursionInfinita(); end Function recursionInfinita() Begin recursionInfinita(); end Function recursionInfinita() Begin recursionInfinita(); end
  • 16. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 16/68 Hacer un procedimiento recursivo que muestre por pantalla un número dado “n”. EJERCICIO 1
  • 17. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 17/68 Hacer un procedimiento recursivo que muestre por pantalla un número dado “n”. Procedure contar(n: Integer); Begin WriteLn(n); contar(n); End EJERCICIO 1
  • 18. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 18/68 Hacer un procedimiento recursivo que muestre por pantalla un número dado “n”. Procedure contar(n: Integer); Begin WriteLn(n); contar(n); End EJERCICIO 1 Llamada recursiva
  • 19. contar(5) UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 19/68 Hacer un procedimiento recursivo que muestre por pantalla un número dado “n”. Procedure contar(n: Integer); Begin WriteLn(n); contar(n); End EJERCICIO 1 Llamada recursiva UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 19/68 Function contar(n = 5) Begin WriteLn(n = 5); contar(n = 5) end contar(5)Function contar(n = 5) Begin WriteLn(n = 5); contar(n = 5) end contar(5)Function contar(n = 5) Begin WriteLn(n = 5); contar(n = 5) end contar(5)
  • 20. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 20/68 Cada llamada ocupa memoria que nunca se libera, porque ningún procedimiento termina. Computación limitada por tamaño de memoria. Se genera un desbordamiento de pila. ¡ESTO NO SIRVE!
  • 21. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 21/68 1. Llamada recursiva (por definición). 2. Condición de corte. 3. Cada llamada recursiva converge (se acerca) paso a paso a la condición de corte. ALGORITMO RECURSIVO ÚTIL
  • 22. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 22/68 Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen desde un número dado “n” hasta 100. EJERCICIO 2
  • 23. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 23/68 Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen desde un número dado “n” hasta 100. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end EJERCICIO 2
  • 24. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 24/68 EJERCICIO 2 1. Llamada recursiva 3. Acercamiento a la condición de corte 2. Condición de corte Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen entre un número dado “n” hasta 100. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end
  • 25. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 25/68 EJERCICIO 2 procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end contar(98) Impresión (registro de activación)
  • 26. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 26/68 EJERCICIO 2 procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end contar(98) 98 Impresión
  • 27. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 27/68 EJERCICIO 2 contar(98) procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 Impresión 98
  • 28. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 28/68 EJERCICIO 2 contar(98) 98 < 100 (true) Impresión 98
  • 29. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 29/68 EJERCICIO 2 contar(98) contar(98 +1) Impresión 98
  • 30. 99 procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 30/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 Impresión 98
  • 31. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 31/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 99 Impresión 98 99
  • 32. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 32/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 99 < 100 (true) Impresión 98 99
  • 33. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 33/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 contar(99 +1) Impresión 98 99
  • 34. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 34/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 contar(100) procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end 100 99 Impresión 98 99 100
  • 35. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 35/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 contar(100) procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end 99 100 < 100 (false) Impresión 98 99 100
  • 36. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 36/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 contar(100) procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end 99 100 < 100 (false) Impresión 98 99 100
  • 37. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 37/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 99 Impresión 98 99 100
  • 38. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 38/68 EJERCICIO 2 contar(98) contar(99) procedure contar(n: intege begin WriteLn(n); if n < 100 then begin contar(n+1); end end 98 99 Impresión 98 99 100
  • 39. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 39/68 EJERCICIO 2 contar(98) 98 Impresión 98 99 100
  • 40. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 40/68 EJERCICIO 2 contar(98) 98 Impresión 98 99 100
  • 41. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 41/68 EJERCICIO 2 contar(98) Impresión 98 99 100
  • 42. Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen entre un número dado “n” hasta 100 en orden inverso. procedure contar(n: integer); begin WriteLn(n); if n < 100 then begin contar(n+1); end end UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 42/68 EJERCICIO 2b 2° recursión 1° impresión, proceso, acción
  • 43. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 43/68 EJERCICIO 2b 1° recursión 2° impresión, proceso, acción Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen entre un número dado “n” hasta 100 en orden inverso. procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end
  • 44. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 44/68 EJERCICIO 2b 1° recursión 2° impresión, proceso, acción Hacer un procedimiento recursivo que muestre por pantalla todos los números naturales que existen entre un número dado “n” hasta 100 en orden inverso. procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end Backtracking
  • 45. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 45/68 EJERCICIO 2b procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(98) Impresión (registro de activación)
  • 46. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 46/68 EJERCICIO 2b procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(98) Impresión 98
  • 47. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 47/68 EJERCICIO 2b procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(98) Impresión 98 < 100 (true) 98
  • 48. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 48/68 EJERCICIO 2b contar(98) Impresión procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(98 +1) 98
  • 49. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 49/68 EJERCICIO 2b contar(98) Impresión procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99
  • 50. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 50/68 EJERCICIO 2b contar(98) Impresión procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 99 < 100 (true)
  • 51. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 51/68 EJERCICIO 2b contar(98) Impresión procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 contar(99+1)
  • 52. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 52/68 EJERCICIO 2b contar(98) Impresión procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(100) 100 100 < 100 (false)
  • 53. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 53/68 EJERCICIO 2b contar(98) Impresión 100 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(100) 100 100
  • 54. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 54/68 EJERCICIO 2b contar(98) Impresión 100 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(100) 100
  • 55. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 55/68 EJERCICIO 2b contar(98) Impresión 100 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99
  • 56. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 56/68 EJERCICIO 2b contar(98) Impresión 100 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99 99
  • 57. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 57/68 EJERCICIO 2b contar(98) Impresión 100 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end contar(99) procedure contar(n: integer begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 99
  • 58. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 58/68 EJERCICIO 2b contar(98) Impresión 100 99 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98
  • 59. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 59/68 EJERCICIO 2b contar(98) Impresión 100 99 98 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98 98
  • 60. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 60/68 EJERCICIO 2b contar(98) Impresión 100 99 98 procedure contar(n: integer); begin if n < 100 then begin contar(n+1); end WriteLn(n); end 98
  • 61. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 61/68 EJERCICIO 2b contar(98) Impresión 100 99 98
  • 62. Algoritmos Recursivos Vs Algoritmos Iterativos UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 62/68
  • 63. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 63/68 Hacer un procedimiento iterativo equivalente al ejercicio 2. EJERCICIO 3
  • 64. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 64/68 Hacer un procedimiento iterativo equivalente al ejercicio 2. EJERCICIO 3 Recursivo procedure contar(n: integer); begin WriteLn(n); if n < 100 then contar(n+1); end Iterativo procedure contar(n: integer); begin do WriteLn(n); n := n + 1; until n >= 100 end
  • 65. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 65/68 Hacer un procedimiento iterativo equivalente al ejercicio 2. EJERCICIO 3 Iterativo procedure contar(n: integer); begin do WriteLn(n); n := n + 1; until n >= 100 end1. Llamada recursiva / bucle 3. Acercamiento a la condición de corte 2. Condición de corte Recursivo procedure contar(n: integer); begin WriteLn(n); if n < 100 then contar(n+1); end
  • 66. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 66/68 OBSERVACIONES Recursión lineal - Una sola llamada recursiva. - Puede ser reemplazada por un bucle while fácilmente. - Sirve para recorrer estructuras lineales como arrays o listas.
  • 67. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 67/68 OBSERVACIONES: Utilidad de la recursión Recursión binaria - 2 llamadas recursivas dentro de cada bloque. No se puede reemplazar por un bucle while fácilmente Sirve para recorrer estructuras de árboles y grafos Problemas de naturaleza recursiva
  • 68. UTN – FRLP – Concurso Sistemas Operativos 2014 - Ing. Julián Perelli 68/68 Recapitulación Recursión: Usos comunes Definición Definición + utilidad Backtracking Recursión vs while Observaciones finales: utilidad