What is recursion?

Open a browser and type “recursion” on Google. Did you notice the “Did you mean: recursion” message?

Photo by author. Screenshot of Google.

Click on that message. It will appear again. Click again. There it is again. Click it… OK, enough.

You’re now beginning to understand what recursion is. If you scroll down on that very same Google page, you will see this:

“Recursion: the repeated application of a recursive procedure or definition.”

Even recursion’s own definition is recursive.


Recursion in Programming

In programming terms, recursion happens when a function calls itself.

If you have a problem that is too complex, you can use recursion to break it down into simpler blocks. You do this in real life all the time. Imagine you have a whole box full of $100 bills and you need to count how much money you have. Since it’s a lot, you might ask for the help of your friend, and you divide the stack in two. When you both finish counting, you add up your results and get the final number.

It would be the exact same total if only one of you counted it all — you just took a different road. In programming, this road is called recursion, and the alternative road is called iteration.

So when should you use one or the other?

#java #coding #startup #programming #technology

Understanding Recursion With Examples
1.45 GEEK