Saturday 28 February 2015

Week 7: Pimp My Function


 CSC 148 Entry 6

     Yo dawg I heard you like to write functions, so I made you a function that calls on itself so you can use the function to iterate through trees and other types of data structures.


     The more I learn about recursion the more I am impressed by the various possible things which can be done with recursion. For example, we learned how to iterate through lists nested in lists. When I originally saw the problem I was thinking of possible convoluted solution to the problem. However, the solution was so simple and elegant.

if isinstance(variable, list):
     return something([funciton(x) for x in variable])

This solution to the problem of iterating through the nested lists seemed so rudimentary yet complex at the same time. It really touched me and and I had a thought that this is what computer science is about coming up with elegant solutions to problems instead of brute forcing them. From then I see recursion in a new light.

     Most of the problems posted in lab 5 and 6 required the use of recursion to solve and this was actually quite challenging to try and solve. The problem was because it was a lot of work and that it required a lot convoluted code to solve; the problem was trying to wrap your mind around the concept of how the function would run over and over again and the possible cases which there are. I found the advice which Professor heap gave in lectures to think of all the different possible cases starting with the base case extremely helpful because it gave me a focus to start off from and eventually solve the problem.

    Although I found the recursive problems very hard, the more problems I see, the more simpler recursion seems. I think this is because all of the solutions to the problems are very similar. You just have to focus on the bases case, accounting for different scenarios and write the recursive step. When working on minimax I found it really helpful to draw diagrams of what is going to happen in each case, I think this is the key to recursion, its not how it will be implemented it's thinking of the conditions for the recursive function. After knowing what to account for the code basically writes itself.

No comments:

Post a Comment