The topic of this week is about recursion. In my opinion,
recursion is one of the most difficult parts in csc148, but it is also the most
useful part. It can help us make the code simpler and convenient. At the
beginning of this semester, I started to get some knowledge of recursive
function. When I did the assignment 1, using recursion is the most important
part. I needed to decide when I should use the recursion and understood how
recursion works. For example, moving cheeses with 4 stools needs us to think
about how to move cheeses with 3 stools, how to get the result with the
smallest steps, and how to use the destination stool and intermediate stool
correctly. In addition to the moving cheeses, getting the greatest common denominator
and binary representation both are about recursive function. Recursion helps us
solving problem more efficiently because we don’t need to write too many codes.
The lab of this week is about linked list. My partner and I didn’t
finish. We spent too much time writing long and difficult codes and when we ran
it, always got error. Using recursion to get the length of a linked list is
much easier.
This week I also learned something about Fibonacci sequence
in math lecture. Recursion helps me understand the sequence well. Recursion is not
only used in computer science, but also used in math. I know recursion is very
helpful, but does the recursion have some diadvantages?
With recursion you should consider the intermediate steps, which is exact the reason that with recursion your code can be cleaner. Otherwise you should use loop.
回复删除