0% found this document useful (0 votes)
38 views8 pages

Recursion: Paul Leandro Lanot College Lecturer, Sics

Recursion is a technique for solving problems by breaking them down into smaller subproblems and solving those subproblems in the same recursive manner. It involves defining a simple base case and a set of rules to reduce all other cases toward the base. For example, a recursive function for calculating factorials works by calling itself with decreasing inputs until a base case of 1 is reached, at which point it returns without further recursion. Recursion is useful for problems that can be divided in this way and is commonly used in algorithms for trees, graphs, and other divide-and-conquer approaches.

Uploaded by

Raiza Ananca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views8 pages

Recursion: Paul Leandro Lanot College Lecturer, Sics

Recursion is a technique for solving problems by breaking them down into smaller subproblems and solving those subproblems in the same recursive manner. It involves defining a simple base case and a set of rules to reduce all other cases toward the base. For example, a recursive function for calculating factorials works by calling itself with decreasing inputs until a base case of 1 is reached, at which point it returns without further recursion. Recursion is useful for problems that can be divided in this way and is commonly used in algorithms for trees, graphs, and other divide-and-conquer approaches.

Uploaded by

Raiza Ananca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

RECURSION

PAUL LEANDRO LANOT


COLLEGE LECTURER, SICS
WHAT IS RECURSION?

Recursion is a way of solving a problem


by having a function calling itself
EXAMPLE IS A RUSSIAN DOLL
WHAT IS RECURSION?
Recursion is a way of solving a problem by having a function calling itself

Performing the same operation multiple times with


different inputs.

In every step we try smaller inputs to make the problem


smaller.

Base condition is needed to stop the recursion,


otherwise infinite loop will occur.
RUSSIAN DOLL IN PROGRAMMING
WHY RECURSION?

Recursive thinking is really important in programming and it helps you break down big problems into
smaller ones and easier to use
 When to choose recursion?
• If you can divine the problem into similar sub problems
• Design an algorithm to compute nth
• Write code to list the n
• Implement a method to compute all.
• Practice

The prominent usage of recursion in data structures like trees and graphs

It is used in many algorithms (divide and conquer, greedy and dynamic programming)
HOW RECURSION WORKS?

1. A method calls it self


2. Exit from infinite loop
HOW RECURSION WORKS INTERNALLY

You might also like