0% found this document useful (0 votes)
13 views6 pages

Recursion

Uploaded by

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

Recursion

Uploaded by

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

Recursion

A method that calls itself is known as a recursive method.


And, this process is known as recursion.
Example
Writing a Recursive Function?

• Base Case is a small problem that we know how to solve and


is the case that causes the recursion to end. In other words,
it is the case whose solution is pre-known.

• Recursive case: is the more general case of the problem


we’re trying to solve using recursive function.
Recursion v/s Iteration
Recursion Iteration
Recursion uses selection structure. Iteration uses repetition structure
.

Recursion terminates when a base case is An iteration terminates when the loop condition
recognized. fails.

Recursion is usually slower than iteration due to An iteration does not use the stack so it's faster
the overhead of maintaining the stack. than recursion.

Recursion uses more memory than iteration. Iteration consumes less memory.

Recursion makes the code smaller. Iteration makes the code longer.
All recursive algorithms must obey three important laws:

• A recursive algorithm must have a base case.


• A recursive algorithm must change its state and move toward the
base case.
• A recursive algorithm must call itself, recursively.

You might also like