Wednesday, 24 February 2016

The "real" week 6

I suppose this week is actually week 6, since last week was reading week, and I guess I'll stick to the way the university counts weeks. This week in class has been exciting, we're finally getting around to recursion, something I've heard lots about and so have been anticipating. It seems like an incredibly powerful tool. The concept isn't too hard to grasp though understanding how its implemented by the computer is a little tough. After you trace through a couple nested list examples, though, it's really not too bad. I think it's a really neat, and clever, idea.
I thought at first, like many others, that it didn't make sense for a function to be able to call itself, and I was wondering how it wouldn't just get stuck in an infinite loop. The key is that the function has conditional statements within it (if, elif, else). If one condition, one "if" makes use of recursion, as long as the recursion eventually yields results that, when put back into the function as an argument, no longer satisfy this condition (let's say they don't satisfy the "if" but now they satisfy the "else") then the function will have an endpoint, it won't be infinite. And really, I guess, that's the trick to recursion. It seems to me, with my limited programming knowledge that is, that without conditional statements, or something that mimics them, recursion would break down.
It seems that whenever the method (or algorithm) you use to solve the problem as a whole is applied in exactly the same way to any of its parts then recursion is a good idea. It should allow us to take very complicated problems and break them down into a series of much easier problems once we recognize that the method for solving the problem is the same at every level. I'm really interested to see what kinds of things we can apply this idea to.

No comments:

Post a Comment