In high school computer science, I was taught recursion, but because of the way it was taught I could not see the advantage of using recursion over a simple for or while loop. In this course, the challenge of determining how many layers "deep" a given list is proved to be a very practical way of showing why recursion is a necessary tool for any programmer. Since a list can have any number of lists within lists it would very difficult to write a loop for any n depth of list. I could not think of a method to tackle this problem with only a loop. However this problem is solved in just 4 lines using a recursive method. This was an excellent example of the importance of a computer scientist understanding recursion and using it as a tool in their programs.
No comments:
Post a Comment