Week
11
Visit to an earlier SLOG poster of mine
It seems to me that “Introduction to Computer Science” has recursion as its main focus of study. We are close to the end of the semester, and I have realized that we spent two thirds of the course discussing this topic. For this reason, I would like to revisit my earlier post on recursion in order to get a fresh insight and to master the concept.
The post I am revisiting has as title: “Week 7
Recursion/ Math connection”. It deals with recursion and its use in lists and
trees, as well as the connection with mathematical notions. Back then I wrote “It is
interesting to see that basically the same concept can be applied, no matter
which object we are working with.” Having work with recursion, for
around 5 months by now, I can confirm this statement. Indeed, recursion is in every
process that aims to repeat a task a considerable number of times. Thus, this
concept is not limited to lists, and trees.
Moreover, although I did not emphasize it
in the post, I now notice that recursions dealing with lists and trees share
the same logic. We can actually think about lists in terms of nodes. For
instance, imagine we have a list (node) which contains some elements (children
nodes). Once this notion is clear we can follow exactly the same logic, and
creatively apply the recursive function to the elements of the lists, which are
no other thing that the children nodes of the tree. The connection may be more
noticeable when looking at the following code:
Recursive step for a list
return sum([sum_list(x) for x in L])
Recursive
step for a tree
return sum([leaf_count(child) for child in t.children])
In the code above, I have purposely
coloured the parts that seem to be different and left the parts that are equal
in black. As you may have noticed, the corresponding coloured parts have the
same functionality. Therefore, we can conclude that the process of recursion
indeed follows the same logic.
It is also important to notice that the process
of using a case and a recursive step also remains intact for both lists and
trees, and in fact for any other function using recursion. Therefore, it is
always a good idea to carefully look at the following “if else framework”
before the exam:
if (condition): #Base Case
else: #Recursive Step
Peers
reactions about the topic
By looking at other people’s slogs, I noticed that some
people are having problems with understanding recursion. For instance, Dottori
states: “I have decided to revisit last week's (week 10's) post, as it
describes the continuing struggle I have faced with grasping and mastering
recursion.”
As I told this person, mastering recursion is about realizing that we are just making our children nodes do our work:
http://dottoripy.blogspot.ca/2015/03/week-11-revisiting-previous-post.html?showComment=1427680678374#c4600756507989807541
However, there are other people who have been able to
wrap their head around the topic. For instance, Rod claims that practice has
made him become more confident about recursion:
http://rodcsc148.blogspot.ca/
Finally, since I know that evaluating peer interaction
is difficult, I would like to include some of the links of the blogs and
discussions I have taken part in, here:
· http://hayleylincsc148experience.blogspot.ca/2015/03/week-5-term-test-and-recursion-continued.html?showComment=1425821803323#c2948885543747290257
· http://leopharandcsc.blogspot.ca/2015/02/week-4-lol-lots-of-learning.html?showComment=1425823356912#c9171090264996370596
· http://slogwhygeeksshouldwrite.blogspot.ca/2015/02/week-6.html?showComment=1425825049576#c3125285132158934534
· http://tonieewtbeageek.blogspot.ca/2015/01/why-should-geeks-write.html?showComment=1425825836153#c8369804375529975109
· http://thisishomeofrui.blogspot.ca/2015/01/csc148week3.html?showComment=1425826429711#c2034789993238378983
· http://wajw.blogspot.ca/2015/01/why-geeks-should-write.html?showComment=1425826736289#c1558642776147235726
· http://csc148slog2015.blogspot.ca/2015/03/week-8-slog.html?showComment=1426275226075#c4220407772723293115
· http://kirincao.blogspot.ca/2015/03/normal-0-10-pt-0-2-false-false-false-en.html?showComment=1426276256796#c5202222069714805659
· http://darkfoxnewslog.blogspot.ca/2015/03/slog-for-week-9.html?showComment=1426904314181#c8008980281488216210
· http://148choi.blogspot.ca/2015/03/week-9-my-impressions-of-week-8.html
· http://dottoripy.blogspot.ca/2015/03/week-11-revisiting-previous-post.html
· http://dottoripy.blogspot.ca/2015/03/week-11-revisiting-previous-post.html?
howComment=1427680678374#c4600756507989807541
· http://rodcsc148.blogspot.ca/







