Sunday, 8 February 2015
CSC148 Slog 3
This week's lecture is mainly about recursion, which is a function calling itself in its body. And this method is useful for solving problem such as with duplicate same features, for example, calculating the sum in [1,[1,2],[[[1]]]]. In this example, square bracket appears many times and some of it is useless. Therefore, it is more efficient to solve this kind of problem with recursion. However, this kind the of problem can also be solved by using for loop, but recursion is easier to understand and trace bugs. Furthermore, during the trace of recursion, we can simply trace the easy example first, and then we can conclude the result of complicated examples by the previous result. For example, if we know the input of integer will return 1, and a list will put all integers in that list into integer, then we can conclude that the list will return number of integer in that list. In conclusion, recursion is a very useful method.
Labels:
CSC148
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment