Friday, 26 February 2016

CSC 148 Python Week 7 Slog: Recursion for efficiency?

This week, we got introduced to Recursion algorithm and the professor gave us some real world examples and explained the tracing inside of the recursion functions. Recursion means “defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective. For example, we might say “An egg is something who gives birth to a chicken and then gives birth to an egg again”. When we use this algorithm in python programming language, we can find out that in order to solve a problem, functions can call themselves to solve smaller sub-problems. This kind of algorithm is more efficient to some extent comparing to using for loop and while loop for this kind of problems as it will be more complicated to use loops. From the following graph, we can see the difference between recursion and loops.



During the class time, in order for us to better understand this term, the professor gave us some examples which I find it really useful. The professor tried to help us understand more about the recursion algorithm by using tracing the inside of the algorithm step by step. He gave us many examples and explained very patiently and I understand more after his explanation. We also do some in-class exercises about tracing recursion and this really helps us understand deeper about the inside algorithm of it. Thus, in the future study, I will try to understand more about the internal algorithm of different functions and methods and do more exercise to enhance my study.

During the class, the professor asked us whether Recursion is a method for efficiency. I am surprising find out that the professor explain why it is not a way for efficiency. He explained that because there are different methods to solve problems other than loops and recursions, different methods are suitable to solve different problems and thus we should use different methods at different times. In this way, we cannot say that Recursion is created for efficiency. 

No comments:

Post a Comment