Week #7: Summary on Recursion
Now I will summarize on tracing the recursive functions, writing recursive functions and talking about 'Tree'.
Firstly, let us think about what we should do in tracing the recursive functions. As we discussed in week 5, the most important thing is not what the answer your get by tracing a single case, but what the function wants to do with the attribute. We may easily trace a function case by case by using the result we have get in previous cases, for it is an instinct that using old tools to fix new problems. I think that we use recursion for we want the computer to inherit that instinct. The code we write is an extension of our mind, a baby of our mind, or even a clone of our mind! So what the function wants to do is just what the programmers want to do. That is the only reason for us to trace the function and use the function -- to do what the programmers want to do.
Secondly, what I have learned in the lecture and tutorial is to write my own recursive functions. At the beginning of writing recursive function, I find it really hard to write the code dealing with much harder cases by using the function itself again and again. For sometimes, we may find it difficult to decide whether to use sum() or max() or all() or any() or adding 1 to sum(), to max() or something even more stranger. How do we know what built-in function do we need to use for recursion? It depends on the purpose we write the recursion, that is I emphasize in the previous paragraph-- what the function wants to do with the attribute. As for the example count_list(), by the docstring, we know that we are going to count the number of lists in a possibly-nested list. So what built-in do we need to use? Apparently, it is 1 + sum() for the words: 'the number of'. Another situation, if we want to compare something, we may use max() or min() instead. Or we want to return a boolean, we may use all() or any() representing 'and' or 'or'.
Finally, I want to talk about stack, queue and Tree. Stack and queue are just like a pair of brothers. Stack is to remove the last element in the list, while queue is to remove the first one in the list. But when adding a new element to the list, they both add it to the end of the list. As for Tree data structure, we have introduced both Tree and binary Tree. We can see the concept of a Tree in the picture. I think that the Tree class is not only designed to practice writing recursions, but to build a mind of thinking problems using the Tree data structure. Just like what we do in assignment 2. We analyze the minimax strategy by dividing each possibility of next state to a child node of the root node. And we just need to analyze the leaf node, that is a win state or a tie state. That helps us to determine the current score of each player and help the players to decide which is the best move they should take in order to win the game.
In conclusion, recursive functions and Tree data structure is what we focus on in the previous weeks, and we need to keep them in mind when solving problems related to analyze the situation by analyzing a more original one.

Wow, interesting approach for recursion method. Great work!
ReplyDeleteThank you for appreciating my slog, feeling the beauty of recursion and computer science!
DeleteWow, interesting approach for recursion method. Great work!
ReplyDeleteThis was a really interesting slog covering recursion. Tbh I have actually learned something from reading it. Good Work.
ReplyDeleteThis was a really interesting slog covering recursion. Tbh I have actually learned something from reading it. Good Work.
ReplyDelete