I think that the most important and
most focused on concept of CSC148 has so far been recursion. This is
a powerful way of approaching programming which I was not previously
aware of. However, I think that recursion is an intuitive concept
which everyone can grasp. In computer science specifically, recursion
is when a function or method calls itself in order to achieve a task.
Recursive functions generally have a base case which tell them what
to do when a certain point in the execution has been reached and
recursion is no longer necessary (as to prevent infinite recursion).
A simple way of understanding recursion is to look at an visual
example of it, such as the one I provided below. In very basic terms,
something that is recursive contains itself within itself.
Recursion is so useful because of how
flexible it allows code and functions to be. In the nested depth and
sum list examples we worked on in class, the functions took the
nesting depth and sum of the list, regardless of how many nested
lists there were. Without recursion, these functions would only work
for certain configurations of lists and nested lists. Some functions
or formulas cannot exist without recursion, as seen in the first
assignment, where the formula for the minimum amount of moves called
itself, as well as in the function which solved a three stool Hannoi
game. Recursion also saves time; writing a base case and a general
case is much less time consuming than thinking of every possible
input or combination. Trees and linked lists (as seen this week) are
ADTs which are recursive, so certain methods written for these data
types naturally involve recursion and cannot be properly used without
it.
I now feel that I understand recursion
fairly well. The term test written this week seemed to not be
overwhelming for me, and I also started the second assignment, but am
somewhat confused about how to approach it. The linked list examples
that we went over in class made sense to me and I saw how they are
recursive in nature.
Recursion explained through a demotivational poster.
http://img.photobucket.com/albums/v394/civilwarman/recursion.jpg