Recursion | Iteration |
---|---|
Recursion is at top-down approach. | Iteration is a bottom-up approach. |
When a function call itself it is called as Recursion. | In Iteration, set of statements is executed repeatedly until some specified conditions is satisfied. |
Recursion is based on 'base condition', execution of statement moving towards base condition. | Iteration is based on initializtion, termination, updation and execution. |
Recursion runs out of the memory if the base condition is not met. | Iteration results in infinite loop if the termination condition is not met. |
Recursion takes more space to store new sets of local variables. | Iteration does not take as much space compared to recursion. |
Every recursive algorithm can be converted into its iterative version. | Every iteration cannot be converted to recursive version. |
Recursion helps to keep our code short and simple. | Iteration approach makes the code longer. |
Recursion is slower than itertion due to maintenance of stack. | Iteration is faster than recursion. |
It is complex to implement. | It is simple to implement. |
Instead of making use of 'for, while, do-while' mostly in the code execution we try to call the same function again and again. | The iterative function are implemented with the help of 'for, while, do-while' programming constructs. |
Difference between Recursion and Iteration
About Vipul Singh
Editor-in-Chief and Owner of TechBlogMU. Computer Engineer, Data Science Enthusiast and Tech Blogger. Catch him on Facebook and Twitter
Become a Patron: https://www.patreon.com/techblogmu
Subjects
- Artificial Intelligence (AI)
- ASP.NET with C#
- Big Data Analytics
- Computer Networks
- Cryptography and System Security
- Data Structures
- Data Warehouse and Mining
- Database Management System
- Digital Signal Processing
- Human Machine Interaction
- Machine Learning
- Microprocessor
- Object Oriented Programming Methodolgy (OOPM)
- Operating System
- Parallel and Distributed Database
- Software Architecture (SA)
- Statistics
- Structured and Object Oriented Analysis and Design (SOOAD)
- System Programming and Compiler Construction (SPCC)
- Theory of Computation