- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Recursion is useful in dividing and solving problems. Each recursive call itself spins off other recursive calls. At the centre of a recursive function are two types of cases: base cases, which tell the recursion when to terminate, and recursive cases that call the function they are in. A simple problem that naturally uses recursive solutions is calculating factorials. The recursive factorial algorithm has two cases: the base case when n = 0, and the recursive case when n>0 .

Backtracking is a general algorithm for finding solutions to some computational problem, that incrementally builds choices to the solutions, and rejects continued processing of tracks that would lead to impossible solutions. Backtracking allows us to undo previous choices if they turn out to be mistakes.

A typical implementation of the factorial is the following -

def factorial(n): #test for a base case if n==0: return 1 # make a calculation and a recursive call f= n*factorial(n-1) print(f) return(f) factorial(4)

This code prints out the digits 1, 2, 4, 24. To calculate factorial 4 requires four recursive calls plus the initial parent call.

- Related Questions & Answers
- What is recursion & backreferences in Python?
- What is Logical AND Operator (&&) in JavaScript?
- What is double address operator(&&) in C++?
- What is different in & and AND operators in Python?
- What is pointer operator & in C++?
- Introduction to Backtracking
- What is JavaScript Bitwise AND (&) Operator?
- What is Interface Testing(Types & Example)?
- What is Static Testing & Testing Review?
- What is Functional Testing (Types & Examples)?
- What is Bitwise AND Operator (&) in JavaScript?
- What is matching concept in finance & accounting?
- What does the &= operator do in Python?
- Introduction to Backtracking Algorithms
- What is dual aspect concept in accounting & finance?

Advertisements