0% found this document useful (0 votes)
27 views27 pages

Intro To Recursio N

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)
27 views27 pages

Intro To Recursio N

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/ 27

Intro to

Recursio
n
What is
Throughout your computer science
journey so far, you’ve most likely heard
of iteration and multiple iteration, which

recursion
is repeating a particular block of code
for a certain amount of times until you
stop

? These are represented as FOR loops


and WHILE loops

But iteration may not be the only way


to solve certain problems, and there
may even be a better way

An alternative way for programming


problem solving is called recursion
What is recursion?
Recursion happens when a function calls We will call this function factorial (int
ITSELF. This can be a strange concept for number)
you to wrap your head around. But it
CAN be done
Recursion
We will be building a recursive function Recursion
to return the factorial of a number. A Recursion
factorial is the product of a number and
Recursion
all the positive integers that are smaller
Recursion
than it
Recursion

(For all intents and purposes, this will be Recursion


in pseudocode so you can use any Recursion
language you want for your examples)
What is recursion?
The factorial function takes in ONE We already know that the factorial of
parameter and that’s the number we 1 is 1, so we can say:
are trying to find the factorial of. Let’s
assume that no-one will input a
number less than 1
if(number ==
There are 2 parts to a recursive 1){
function: return 1;
}
The first is the base case, which is
critical for getting our recursive
function to EXIT
What is recursion?
The next part is the We can write the recursive step as:
recursive step. This is where
we get the function to call
return number *
itself. What do we know
about factorials? That the
factorial(number – 1).
factorial of a number CAN be Our completed function is:
equal to the number itself
[multiplied by] the factorial int factorial (int number) {
of the previous number
if number == 1
return 1
return number *
factorial(number – 1);
}
What is recursion?
Now let’s put a number into this Every time we call the recursive
function as an example and see function, it gets pushed to the top
how we do, and see how recursive of the stack until we hit a base case
functions operate (number = 1). Then that value gets
Let’s try 4: returned and all the recursive calls
get popped off the stack one by
Factorial 4 · Factorial one. 4 * 3 * 2 * 1 = 24, which IS 4!
=
(4) (3)
3 · Factorial This was a small intro to recursion!
(2)
2 · Factorial
(1)
Thank
s
Do you have any questions?
youremail@freepik.com
+91 620 421 838
yourwebsite.com

CREDITS: This presentation template


was created by Slidesgo, and includes
icons by Flaticon, infographics &
images by Freepik and contents by
Swetha Tandri

Please keep this slide for attribution


Alternative resources
Here’s an assortment of alternative resources whose style fits that of this template:

Vectors
● Desktop and smartphone app development
Resources
Did you like the resources on this template? Get them on our other websites.

Vectors
● Flat cms concept in blue shades
Instructions for use
If you have a free account, in order to use this template, you must credit Slidesgo by keeping the Thanks slide. Please
refer to the next slide to read the instructions for premium users.

As a Free user, you are allowed to:


● Modify this template.
● Use it for both personal and commercial projects.

You are not allowed to:


● Sublicense, sell or rent any of Slidesgo Content (or a modified version of Slidesgo Content).
● Distribute Slidesgo Content unless it has been expressly authorized by Slidesgo.
● Include Slidesgo Content in an online or offline database or file.
● Offer Slidesgo templates (or modified versions of Slidesgo templates) for download.
● Acquire the copyright of Slidesgo Content.

For more information about editing slides, please read our FAQs or visit our blog:
https://slidesgo.com/faqs and https://slidesgo.com/slidesgo-school
Instructions for use (premium users)
As a Premium user, you can use this template without attributing Slidesgo or keeping the Thanks slide.

You are allowed to:


● Modify this template.
● Use it for both personal and commercial purposes.
● Hide or delete the “Thanks” slide and the mention to Slidesgo in the credits.
● Share this template in an editable format with people who are not part of your team.

You are not allowed to:


● Sublicense, sell or rent this Slidesgo Template (or a modified version of this Slidesgo Template).
● Distribute this Slidesgo Template (or a modified version of this Slidesgo Template) or include it in a database or in
any other product or service that offers downloadable images, icons or presentations that may be subject to
distribution or resale.
● Use any of the elements that are part of this Slidesgo Template in an isolated and separated way from this
Template.
● Register any of the elements that are part of this template as a trademark or logo, or register it as a work in an
intellectual property registry or similar.

For more information about editing slides, please read our FAQs or visit our blog:
https://slidesgo.com/faqs and https://slidesgo.com/slidesgo-school
Fonts & colors used
This presentation has been made using the following fonts:

Alata
(https://fonts.google.com/specimen/Alata)

Archivo
(https://fonts.google.com/specimen/Archivo)

#041e52 #ffffff #073899 #4f7bc8

#80b2f1 #f4f6f8 #dbe8f1


Storyset
Create your Story with our illustrated concepts. Choose the style you like the most, edit its
colors, pick the background and layers you want to show and bring them to life with the animator
panel! It will boost your presentation. Check out how it works.

Pana Amico Bro Rafiki Cuate


Use our editable graphic resources...
You can easily resize these resources without losing quality. To change the color, just ungroup the resource and click on
the object you want to change. Then, click on the paint bucket and select the color you want. Group the resource again
when you’re done. You can also look for more infographics on Slidesgo.
JANUARY FEBRUARY MARCH APRIL MAY JUNE

PHASE 1

Task 1

Task 2

PHASE 2

Task 1

Task 2

JANUARY FEBRUARY MARCH APRIL

PHASE 1

Task 1

Task 2
...and our sets of editable icons
You can resize these icons without losing quality.
You can change the stroke and fill color; just select the icon and click on the paint bucket/pen.
In Google Slides, you can also use Flaticon’s extension, allowing you to customize and add even more icons.
Educational Icons Medical Icons
Business Icons Teamwork Icons
Help & Support Icons Avatar Icons
Creative Process Icons Performing Arts Icons
Nature Icons
SEO & Marketing Icons

You might also like