Sunday, 23 February 2014

Slog #5 (Week 7) Recursion? Did you mean... Recursion?

Recursion? Recursion. Recursion is really cool. No, seriously. It's like inception. It's probably the best way to describe it. Within a function, we call the function itself. And we do so until we reach the base case of a function. Mind you, every time we call the function, the input has to be different in some form, usually shorter or smaller than the previous input. Recursion has been fairly easy, but with the introduction of binary trees and linked lists, suddenly it has become super hectic. If tracing it wasn't enough, you have things like linked lists which is recursive itself (the tail is the head of another linked list), so you have to deal with like double recursion. Double inception. Woah.

To be more in-depth about recursion, the idea is that we take a problem, and we work at it continuously with the same method, but on a smaller scale each time, until the problem becomes so small, that it is easily dealt with. Now when we work backwards, these small solutions add up back into a big solution. We work with the problem recursively. At times it may be difficult to visually see how it works, but once you get in the mindset of it, it becomes very easy and useful.

Saturday, 15 February 2014

Slog #4 (Week 6) Stumped With Trees

I'll admit, I'm stumped. Like a tree. Heh, get it? I'm not actually stumped, I only said so to use lame puns. So what's the deal with trees? For starters, they aren't like real trees. This week we dealth with binary trees. Think of a blob. And then it grows 2 limbs with blobs at the ends. And those 2 blobs grow 2 more limbs with blobs at the end, and so on. A binary tree is something like that. I really suck at explaining. Simply put, it's another abstract data type. In this case, you have an object that has 0, 1 or 2 children. The max number of children it can have is called the arity factor. Binary trees have an arity/branching factor of 2. No surprise there. But the cool part is that the children themselves are binary trees. It was fairly easy to understand the concept, and it was fun during the labs to explore how to work with the binary trees themselves. The idea of a binary tree's children being binary trees brings back the idea of recursion, and during the labs it helped me refine my ability at being able to do recursive functions more efficiently.

This week is also the week we have to hand in assignment 1. I've spent countless hours reading it, and from what I've managed to code, I think everything is okay. I think the trick is to really read it until it hurts, then read some more. And then hopefully by then it makes sense. If future me is reading this, I hope you ace this project.

EDIT: Woo, we aced it. Hell yea.

Sunday, 9 February 2014

Slog #3 (Week 5) Why I Don't Like Cheese

I don't like cheese. And when assignment 1 has to do with cheese, my hatred for it grows even more. I do like cheese on pizza. And Kraft Dinner. And lasagna.

Okay, seriously though. I've stared at some sections, and I don't get it.

EDIT: I still dont get it

EDIT 2: I GET IT.

EDIT 2.5: On a serious note, today we spent more time refining our ability to code recursively. I think that recursion requires a certain mindset, and that eventually over time one will adapt and be able to use it at ease. One of the difficulties I find with recursion is finding the base case and tracing the recursive program overall. I see recursion as taking a problem and making it smaller, until we are able to tackle the small problem with ease. But tracing our way to the small problem can require so many steps that one can get lost in it. An example is when I tried to use the M(n) (least number of steps) function, I had a difficult time trying to implement it because I wasn't thinking with the proper recursive mindset. But eventually, it clicked. Fellow coders, good luck on assignment 1.

EDIT 3: Oh ho ho you clever *******s.

EDIT 4: In class today, Danny went over the towers of hanoi. One of his explanations helped me get over a ditch I've been stuck in for a few hours now. 

Saturday, 1 February 2014

Slog #2 (Week 4) - Recursion and Lists Comprehensions

Today I learned recursion and lists comprehensions. Okay, enough with the boring formal talk. Heh. Lists comprehensions are pretty sick. I've never actually dealt with it before, so seeing it in action today was pretty cool. Being able to create a list automatically in one line is pretty damn neat.

This week we focused on the theme of recursion, and with a sprinkle of lists comprehension. We worked through some problems such as nested lists, and it really required a certain mindset that I haven't adjusted to yet. Also, doing these problems I learnt about using if and else statements in one line. I thought it was pretty cool to be able to do such a thing. Execute this if this this lines happens to be true, and otherwise this if the line is false. This could make for some pretty short and efficient code, which I am a fan of. Long gone are the days of if and else blocks!