Thursday, 3 March 2016
Week 7!
In class, we have spent a good amount of time doing recursion and looking at examples where recursion makes things easier.Recursion is the process using a function inside itself. A recursive function usually takes form of a function that contains an if statement, and if the condition is true, it calls on the itself with a different parameter. If it is false, the function returns a value. That way, the recursive repeats itself until the parameter does not satisfy the condition.Basically, to sum it all up, there is a base case and the function will repeatedly call itself until the base case is satisfied. It will then go back words and complete the previous calls on itself until the original function call is done.
We have seen an example about going through nested lists. In the example,the if condition consisted of checking if the type of an object is a list. If that condition is true, the function is called on each element of the list. If it is false, it returns the value of the object.
I believe the key to fully understanding recursion is to know how to trace a recursive function. Once you have that down, it becomes fairly straight-forward. Prof. Danny said that recursion will become very important in this course so I am going to try and know all that there is to this interesting concept.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment