Stepan's CSC148 SLOG

___________________Stepan's CSC148 SLOG

Sunday, 2 March 2014

Recursion


Recursion occurs in computer science when a function calls itself in its definition. It is a concept that is hard to grasp but once you do, it becomes a very useful tool. Recursion is used when to evaluate the task the same algorithm is performed again and again converging towards the base case until the solution is evaluated. One might think that sounds a lot like iteration, and that's because the uses of recursion and iteration are similar, one being more or less appropriate depending on the task at hand. 


One of the simplest applications of recursion is finding the n-th term of a sequence that is defined by recurrence relation, meaning each term is implicitly defined by the previous term. One of such sequences is the fibonacci sequence. Using recursion requires to user to define the base case, the outcome that results when the recursive function is able to return a value before calling itself once. The more times the function has to call itself, the further away the initial value is from the base case.



In the case of the function nested_depth the base case is defined for L that is a non list, it returns 0. That means that throughout the calculations, the base case is used whenever the function encounters a non-list, which otherwise allows to cumulate the amount of nesting in a given list.



Some say intelligence as we know it, is the evolutionary result of an ability unique to humans (as far as we are concerned) called metacognition, which basically means "thinking about thinking".  Great philosophers have pondered on this for centuries. 

Today, most have probably heard of the statement: "I think, therefore I am" coined by Rene Descartes, a 17th century philosopher. This statement implies that the whole nature of existence is recursive based on the condition of self awareness.  Fractal patterns produced by recursion are seen all over in nature. Perhaps recursion can be used to approach some of the most fundamental questions about the universe, macro and micro.

pictures: 
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEKSRkftRym5w4PiZ8RM0aXB5eVyoZDFfK5E_kT3ELFpu4_ZP2hIidruUEKOkJYaI82USY5jzc9vY6QisVIDuB3xaHuB8p-3Puzx5gSZIGxF2gzgzCXv4Pfgp_ssBfmqRNOUosE7R3UQ/s1600/recursion.jpg
https://lh5.googleusercontent.com/-huTWn4MTkKw/UYuLcVBsA2I/AAAAAAAAtJE/mR8otMVN0OA/w800-h800/recursion.png
            

No comments:

Post a Comment