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.
Wednesday, 24 February 2016
Thursday, 18 February 2016
Week 6
This week is reading week so it's a nice little break from the responsibility to drag our sleep-deprived bodies across this chilly campus in the mornings. Nevertheless, there's still lots to do in this course. Our first assignment is due in one week today and since every one of my other classes decided to take advantage of our reading week "spare time" and make something due this coming week, I've had to make sure to get my assignment nearly complete before Monday. So far so good. I know professor Danny was warning us that we will accomplish less than we set out to this week, and I know that's true, but I had nowhere to be and I was quite confident I would get this assignment done or almost done before school returns.
The assignment was pretty frustrating at first. I made the mistake of thinking that reading the assignment handout would be enough knowledge to go into it with. That is, I didn't look through each of the python files and try to read the code and see what was going on and what was expected. That cost me a lot of time because I ended up writing a bunch of functions that didn't do what was expected of them by code that implements them later on, but rather what I thought they should do. I also realized I went into the assignment with a pretty fuzzy understanding of how the simulation actually worked. I understood what we were simulating and the basics about it but I didn't really see how the computer was going to implement all of this nor did I quite understand how all of the modules would work together. I got through about 4 and a half modules and learned my lesson. Things starting breaking down in a hurry. I had messed with too much and figured I would cut my losses, devote a few hours to understanding how the program is supposed to work, draw out some pictures, run through the simulation by hand on a piece of paper and ask myself 'Okay, now how would a computer do this?'. I did that and returned to the assignment, and started from scratch since I figured my newly improved understanding could write better code now and in a quicker time than it would have taken me to fix everything step by step. I think that decision paid off. I went through the first 5 modules pretty quickly and noticed a lot of places I went wrong, and in one instance found much more elegant code to implement a function I had done before.
The assignment was also getting on my nerves because it seemed so much less focused than in CSC108. In 108 we were told step by step what we had to do. This assignment kind of just gave us a rough idea and a batch of code and told us to get started. At first I thought this was a fault on behalf of the instructors until I realized this is exactly the kind of situation I'm going to face in a workplace. No one is going to have the time to write out a detailed step-by-step instruction manual for a program we are working on. Instead, I'm going to get half-written code, docstrings, comments and a rough description of what the program is supposed to do. Just like this assignment. And I'll have to take it from there. So actually I'm quite pleased with how this assignment went. I think it was a really valuable learning experience and definitely taught me that taking a few hours before coding to sit down and really understand what needs to be done is indispensable. If I had done that from the start I would have saved myself about 3-4 hours of work. Lesson learned.
The assignment was pretty frustrating at first. I made the mistake of thinking that reading the assignment handout would be enough knowledge to go into it with. That is, I didn't look through each of the python files and try to read the code and see what was going on and what was expected. That cost me a lot of time because I ended up writing a bunch of functions that didn't do what was expected of them by code that implements them later on, but rather what I thought they should do. I also realized I went into the assignment with a pretty fuzzy understanding of how the simulation actually worked. I understood what we were simulating and the basics about it but I didn't really see how the computer was going to implement all of this nor did I quite understand how all of the modules would work together. I got through about 4 and a half modules and learned my lesson. Things starting breaking down in a hurry. I had messed with too much and figured I would cut my losses, devote a few hours to understanding how the program is supposed to work, draw out some pictures, run through the simulation by hand on a piece of paper and ask myself 'Okay, now how would a computer do this?'. I did that and returned to the assignment, and started from scratch since I figured my newly improved understanding could write better code now and in a quicker time than it would have taken me to fix everything step by step. I think that decision paid off. I went through the first 5 modules pretty quickly and noticed a lot of places I went wrong, and in one instance found much more elegant code to implement a function I had done before.
The assignment was also getting on my nerves because it seemed so much less focused than in CSC108. In 108 we were told step by step what we had to do. This assignment kind of just gave us a rough idea and a batch of code and told us to get started. At first I thought this was a fault on behalf of the instructors until I realized this is exactly the kind of situation I'm going to face in a workplace. No one is going to have the time to write out a detailed step-by-step instruction manual for a program we are working on. Instead, I'm going to get half-written code, docstrings, comments and a rough description of what the program is supposed to do. Just like this assignment. And I'll have to take it from there. So actually I'm quite pleased with how this assignment went. I think it was a really valuable learning experience and definitely taught me that taking a few hours before coding to sit down and really understand what needs to be done is indispensable. If I had done that from the start I would have saved myself about 3-4 hours of work. Lesson learned.
Wednesday, 10 February 2016
Week 5
This week pretty much came down to two things for me: try to understand what linked lists are and how they work, and prepare for the test. Well, the test is over now, and while there was nothing particularly challenging about the questions themselves, what was challenging was being able to answer them all in the amount of time given. I felt there was simply too much pressure from the short writing time to really get results that indicated how well we understood the material, but oh well, I know what to expect for next time now.
As for linked lists, this was an ADT I really enjoyed. I spent a good deal of time the other night fiddling with code and doing lab 4 in advance to get a better understanding of these things. At first I was really confused about how the nodes worked and I was under the impression that the next_ attribute of one node simply called the value of the next node, which was a bit silly. I honestly didn't think that drawing the nodes out on paper would help, I figured the image of these little boxes sitting near each other was easy enough to comprehend but I have to admit after I drew the pictures I was writing code a lot more efficiently. It's really useful to have something on a sheet of paper next to you for your eye to follow as you think about how to implement the code and where the code might run into problems.
The material is definitely starting to get tougher and more interesting!
As for linked lists, this was an ADT I really enjoyed. I spent a good deal of time the other night fiddling with code and doing lab 4 in advance to get a better understanding of these things. At first I was really confused about how the nodes worked and I was under the impression that the next_ attribute of one node simply called the value of the next node, which was a bit silly. I honestly didn't think that drawing the nodes out on paper would help, I figured the image of these little boxes sitting near each other was easy enough to comprehend but I have to admit after I drew the pictures I was writing code a lot more efficiently. It's really useful to have something on a sheet of paper next to you for your eye to follow as you think about how to implement the code and where the code might run into problems.
The material is definitely starting to get tougher and more interesting!
Wednesday, 3 February 2016
Week 4
Well, week 4 is starting to pick up. This week we've focused mainly on stacks and lists. I thought stacks were a pretty neat idea, though I admit at first I found them superfluous. I didn't really understand how they differed from or improved upon what lists could already do in Python, but professor Heap's example about balancing parentheses made a lot of sense. Before he explained it I imagined I would take care of the problem using lists. I figured I would add each parenthesis, bracket or brace to a list one after another, and then when I encountered a closing symbol I would just compare it with the most recent addition to the list, and then the next one with the second most recent addition, etc.. But I can see how that solution could get quite complicated, especially when parentheses are being opened and closed inside of another set of parentheses. The stack solution really simplified the problem a lot. I now see the immense value of stacks, though I am having a little trouble imagining what else they could be used for. Oh and we also learned about creating a list whose components are scattered throughout the memory, which I thought was a really cool idea, though I am not sure how Python would implement such a thing. Wouldn't these just be tiny lists? Wouldn't Python still try to get hold of a bunch of adjacent memory slots? I guess I will find out.
Subscribe to:
Posts (Atom)