Wednesday, March 4, 2015

Recursion Recursion Recursion

I find recursive programming to easily be the most confusing topic we have covered so far. In many cases it looks very simple when written out, but is fundamentally more difficult than any other topic that we know. I understand that they all follow the same format; first a base case and then a recursive step. However it took me almost the entire lab to rap my head around the recursive tree questions. They weren't extremely difficult, but it took a lot of trial and error before I could understand it. I realized the trick since each question had practically the same solution but with a different recursive return statement. This excitement quickly died when I tried to begin on assignment two. In the second assignment a Minimax strategy must be implemented which uses recursion. However, I had a hard time understanding how to put the strategy into code. There is no tree class to use yet it follows a very similar format to a tree. I've been googling tutorials and asking friends on how they have implemented their structure but I cant seem to figure out the recursive a part. I understand the base case very well but the recursive step confuses me. I'm sure after more research online and by going over the lecture slides I will understand soon enough.

Edit: So I kept asking myself how to code recursively without a class structure that supports recursion. However, I realized that I don't need such a class. I figured out that creating temporary game states can simulate this effect by running the same code under a changed game state. With this the recursion works perfectly. I'm happy to been able to work this out and once again proved to myself how confusing recursion can be. Aside from that I find the topic to be very interesting because of situations like these. The code that I have written looks so simple, yet there is so much thought put behind me. It boggles my mind what kind of crazy problems you can solve with recursion that is extremely tedious or even impossible with loops. I'm looking to doing more work with this topic. Rock on!

No comments:

Post a Comment