Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • Contact
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • TypeError: Array() Argument 1 Must Be A Unicode Character, Not List array
  • String Manipulation in Python python method
  • What are the reserved keywords in Python Definition
  • How to Pass Python Variables to Javascript Javascript
  • R Tutorial: How to pass data between functions R Programming
  • What is the r programming language R Programming
  • How to connect to your data in Tableau data visualisation
  • TypeError: List Indices Must Be Integers Or Slices, Not Tuple exceptions

Recursion

Posted on May 26, 2020January 16, 2021 By admin No Comments on Recursion

Estimated reading time: 2 minutes

What is recursion?
To start a recursion is looking to solve a problem, by breaking it down into smaller chunks, which contribute to the final answer.

If it is calling itself, then it is commonly known as a recursive function.

By breaking down the problem at hand, it can then lead to a quicker understanding and solution to the problem.

A simple example might help here, explaining through factorial:

4! = 4*3*2*1 = 24
simple factorial example

From studying maths at school, the simple example above breaks down as:

  • The result 24 is a product of all the values from 4 down to one.
  • As each value that makes it up is known, it then can be seen how the result is made up.
  • The above can be viewed as a recursive function as it keeps repeating on itself until it reaches one, the base.
  • The recursion knows there are three steps before it reaches one; this is where the breakdown into smaller chunks comes in.

So it could be broken down as follows:

Step 1
4*3 ---> Not reached one, try again from the start.
Step 2
4*3*2 ---> Not reached one, try again from the start.
Step 3
4*3*2*1 ---> Reached one, so the recursion stops and the result is outputted.

Steps 1 to 3 are the steps within the function it takes until it reaches the base value, where the function stops and outputs the final value calculated.

Attributes of a recursion

  • A function which calls on itself, this is the repeated steps above until it reaches the base of 1, meaning it doesn’t loop infinitely.
  • Must be possible to break the problem down into smaller parts.
  • As the problem gets broken down, it must become easier to solve without further calculations.
  • Once a smaller part has calculated, this just becomes part of the answer to the overall problem.

Things to watch out for when using recursion

  • Ensure you always have a base value; without it, you could encounter an infinite loop.
  • Not having the ability to break up the problem into smaller steps won’t allow the calculation of the final answer.

Why use recursion?

  • It helps to break up a complicated task into smaller bits.
  • Assists a programmer to see what steps have already coded for so can be solved with other functions already written.
  • Where there are multiple recursive functions, allows to see if similarities in steps, hence only need to programme once for them.

A good source to provide further knowledge can be found here Wikipedia – Recursion

Data analytics Ireland

Definition Tags:Data, Data Analysis, Data Analytics, Data Science, recursion explained, recursive function

Post navigation

Previous Post: R Tutorial: How to pass data between functions
Next Post: Tkinter python tutorial

Related Posts

  • What are the reserved keywords in Python Definition

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • What is GITHUB, and should I use it? github
  • How to add a date when a record is created SQL
  • How to Pass Python Variables to Javascript Javascript
  • ValueError: invalid literal for int() with base 10 Value Error
  • YouTube channel lists – Python Lists Python Lists
  • How to import data into excel Python Tutorial
  • What are dimensions in Tableau? data visualisation
  • How To Check For Unwanted Characters Using Loops With Python Python Data Cleansing

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT