What is a recursive function, what does Recursion mean in Programming?
🔹 Recursive functions are functions that call themselves continuously, not in infinity, but until reaching some specified condition.
🔹Recursion is tactic, a concept in development that includes a function or method that calls itself in a recursive way.
Recursive functions can be interpreted sometimes as routines that call themselves in two ways: direct way or indirect way
What is recursion explained by example?
- It is a powerful programming technique which used to solve one or more practical problems and especially situations by choosing a simple way to break the problem into smaller pieces.
One Great example would be
"road-to-home" operation
The recursion solution for this operation would be:
-- Origin: You have your starting point
-- Destination: You are at home, you just arrived
The process of going from your origin to your destination Home, it includes the process of recursion. So it would break it this scenario only:
-- 000111 If you are at Home stop walking, recursion over your reached Home
-- 111000 Otherwise, walk a step closer to the home
The road from origin to home is divided in small pieces: steps, and the road is a recursion itself, you walk step by step (repetitive ) until a condition is met. In our scenario, reach to Home.
Photo by Anthony Reungère on Unsplash
Generally a recursive function, method, algorithm has the logic as following:
=> if a condition deriving from a method you have set solves the problem, then stop the recursion, otherwise simplify the problem more recursively by dividing it in small pieces till to the resolving point.
It's amazing how real-life examples can be used to explain algorithmic and programming concepts. Love what's you do. Kudos Stemians
Excellent work
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit