Recursion is a new but interesting topic
for me. Recursion is very similar to what we called sequence in Math, or like
cell division in Bio. It’s like designing the program to following a particular pattern,
and more importantly, to reusing the program itself and solve some difficult
problem. At first we knew about recursion on the lecture, through exercises to trace the
program step by step, in order to understand what happening inside the program and how recursion works.
Soon, we were going further, trying to
implement a specific program. The first
easy recursion program is depth, which is an extremely basic example of recursion.
We are following a pattern that first determine input is list or not, if yes
then execute the first way which reuse the program itself; if no then return
something. After the basic case, then we found a short cut. That's every time we write
a recursion function, we can first implement the easy case(base case), usually it's like if some
situation happen, then directly return a number or something simple. Then we
could implement the more difficult cases. Thus, I think this style to
design a function is very similar to the Induction method, which we've learnt
in CSC165 and also Math course.
At
the end, I want to mention some confusion in this chapter’s exercises. First, I’m not comfortable with the concept
of node. What is Binary tree node? I’m not 100% sure, but according to my
understanding, we can image node as a triangle model, which has root at the
very top, or we call it self.data in the exercise. Then it’s not necessary, but
usually node has left leaf and right leaf. And we can combine many nodes to a
Binary Tree. Second, can self.data be anything, not only to be number? Since in
the exercise, function ‘evaluate’ uses operation symbol as its self.data.
没有评论:
发表评论