Looking back on some older posts from week 3 or so I realize how much we've covered in this class so far. I forgot we began by thinking about inheritance and composition and I find it interesting how I can still recall what those terms mean and how they've become second-nature to me now. In week 4 I couldn't imagine how Linked Lists could be implemented without themselves just being composed of python lists. At that point I really didn't see how versatile class-building could be. I thought python had certain data types already and all we could do was slightly alter how they operate. While it's true at some level all we are doing is altering these basic python data types whenever we create a class we are also altering and combining and manipulating them in such incredible ways they really can be almost unrecognizable after it's all done. I couldn't see to get past the idea that anything we wanted to behave as a list must inherit a list or be composed of a list. This class has really awoken me to how different ADTs and classes can be developed and the power behind them.
Wednesday, 30 March 2016
Week 11
I'm looking back on my "real" week 6 entry about recursion and am noticing I've learned a few things since then. In week 6 I figured the only way to implement recursion was to have if statements in your code that could eventually get to a point where the recursive calls end. The thing is, I'm not sure if this is the only way to do it, though I still think it is, but in week 6 I was envisioning these if statements and all of the information they received as being completely contained in the body of the function. But while writing code for this second assignment, mainly for the depth first search, I made use of variables in a different way then I had thought of before - global variables. I wrote code that updated these global variables and, most importantly, one of them was directly used to prevent a branch of code containing a recursive call from being accessed. And in one of the last few lectures we also saw that you could add an argument to the function that gets updated with each new recursive call, and this argument can take on a value that effects an if statement appropriately. So, while I still think if statements probably are the only way to do it (I suspect the more advanced and sneaky code that is recursive must still contain some idea of an if statement or a condition), I'm seeing that the ways in which these if statements work is not always dependent on code that seems strictly contained in the function body… global variables and "outside" things can impact it too.
Week 10
We wrote the second term test. It was much more code-focused than the first test, which evaluated us more on our communication skills - writing docstrings especially. Though the content of this second test was definitely harder than the first I felt the two were roughly about the same level of difficulty, though the second was slightly more challenging. Thankfully, unlike the first test, there was enough time to write this one without feeling extremely rushed to complete it. Though, to my downfall, when there were 10 minutes left and I was looking my paper over I jumped up at the chance to leave early rather than continue looking my work over, and, as always is the case, realizing as I was walking from the exam that I had made a mistake. Well, either way, I'm happy with how the test went all in all.
This week we concentrated mostly on algorithm running time and Big Oh. We're doing Big Oh in csc165 at the moment and really the concept isn't too difficult. I do find counting the steps and judging the running time a little challenging though. I have to work through it quite slowly at the moment. After this second assignment I really see how important running time is. It makes me kind of worried that running time will be a primary concern from this point onwards because it's a little hard to compute. But I guess I have to get practicing it now so that I can do it later when it matters. The puzzle-solving algorithms really varied drastically in performance between puzzle type and algorithm type (breadth first or depth first search) and sometimes small tweaks to the code could improve the running time substantially. Most of the time it was pretty logical why certain modifications would make a running time difference. Loops are always to blame! Without loops the function is always in O(1) but as soon as there are loops of some kind the code takes more and more time to run - loops that are dependent on the data in the function's arguments that is.
*Edit: my week 10 post had difficulty publishing and when I came back to it I found only a third of it saved as a draft when I thought it was published in full. So I've just added the text that somehow got deleted.
This week we concentrated mostly on algorithm running time and Big Oh. We're doing Big Oh in csc165 at the moment and really the concept isn't too difficult. I do find counting the steps and judging the running time a little challenging though. I have to work through it quite slowly at the moment. After this second assignment I really see how important running time is. It makes me kind of worried that running time will be a primary concern from this point onwards because it's a little hard to compute. But I guess I have to get practicing it now so that I can do it later when it matters. The puzzle-solving algorithms really varied drastically in performance between puzzle type and algorithm type (breadth first or depth first search) and sometimes small tweaks to the code could improve the running time substantially. Most of the time it was pretty logical why certain modifications would make a running time difference. Loops are always to blame! Without loops the function is always in O(1) but as soon as there are loops of some kind the code takes more and more time to run - loops that are dependent on the data in the function's arguments that is.
*Edit: my week 10 post had difficulty publishing and when I came back to it I found only a third of it saved as a draft when I thought it was published in full. So I've just added the text that somehow got deleted.
Wednesday, 16 March 2016
Week 9
This week in CSC148 is the week of our second term test, so I've been focusing my energy on LinkedLists, Trees and Binary Trees. I found LinkedLists somewhat confusing the first time we went through them because I didn't have a good grasp of how L.front, L.back and L.size were functioning and I also was getting confused about what kind of object L.next_ is. Once I realized L.next_ was a LinkedListNode (or None) and not just a value like L.value it started getting clearer to me how all of this was supposed to work. I think my first time playing with LinkedLists I was assigning regular values to L.next_ and so print(L) was returning what looked correct but really the LinkedList was ruined and I later realized all of this when I tried doing L.append( ), etc.
For term test 2 I decided to work through all of the example functions provided to us for LinkedLists and Trees - there were quite a bit - but rather than use a computer and an IDE I stuck to pencil and paper. After I was confident with a solution I typed it up and tried it out and determined what, if anything, had gone wrong. I found this method to be extremely effective. I wouldn't say I studied for a particularly long time for the test, but my studying really paid off. Without the convenience of being able to run your code instantaneously and then mindlessly alter a few things here and there until it works, pencil and paper actually forced me to sit and understand what I was doing and go through the logic of it. It definitely increased my understanding of how LinkedLists and Trees worked and I really found that the mistakes I made I made only once or twice before learning my lesson (probably because I wasn't thoughtlessly changing code until I got it right but legitimately working through it).
This is definitely going to be my go-to study method in the future.
For term test 2 I decided to work through all of the example functions provided to us for LinkedLists and Trees - there were quite a bit - but rather than use a computer and an IDE I stuck to pencil and paper. After I was confident with a solution I typed it up and tried it out and determined what, if anything, had gone wrong. I found this method to be extremely effective. I wouldn't say I studied for a particularly long time for the test, but my studying really paid off. Without the convenience of being able to run your code instantaneously and then mindlessly alter a few things here and there until it works, pencil and paper actually forced me to sit and understand what I was doing and go through the logic of it. It definitely increased my understanding of how LinkedLists and Trees worked and I really found that the mistakes I made I made only once or twice before learning my lesson (probably because I wasn't thoughtlessly changing code until I got it right but legitimately working through it).
This is definitely going to be my go-to study method in the future.
Tuesday, 15 March 2016
Week 8
In week 8 of CSC148 we continued on with recursion. This time we explored Trees in more detail and also worked on Binary Trees. We we given a pretty long list of functions to implement for Trees, which turned out to be good practice for recursion. The first couple solutions were all pretty straight forward and it became easy to move into the following functions somewhat mindlessly, assuming the same "simplest case" would continue for the other functions and that the recursive code would all be similar. It was a good wake up call and reminder that you can't really go on autopilot while doing this stuff. Recursion is difficult and really takes a lot of playing around with, I'm finding, to get comfortable with how it works.
Binary Trees, at least, seem much easier to work with than regular Trees. This is probably because their property of having arity less than or equal to 2 makes their structure more predictable. We are also shown some nice examples of Binary Search Trees near the end of the week - Binary Trees whose values are all comparable and whose values run from smallest to largest as you move from the left-most node to the right-most node of the Tree. You can search for values in this kind of Tree very effectively. The way we searched for values in the BST, by judging whether each node was less than or greater than or equal to the value we were searching for, really reminded me of using binary search on sorted lists.
The second term test is next week and I'll have to get studying soon. The two main topics on the test are LinkedLists and recursion, both of which are the hardest things we've learned thus far.
Binary Trees, at least, seem much easier to work with than regular Trees. This is probably because their property of having arity less than or equal to 2 makes their structure more predictable. We are also shown some nice examples of Binary Search Trees near the end of the week - Binary Trees whose values are all comparable and whose values run from smallest to largest as you move from the left-most node to the right-most node of the Tree. You can search for values in this kind of Tree very effectively. The way we searched for values in the BST, by judging whether each node was less than or greater than or equal to the value we were searching for, really reminded me of using binary search on sorted lists.
The second term test is next week and I'll have to get studying soon. The two main topics on the test are LinkedLists and recursion, both of which are the hardest things we've learned thus far.
Wednesday, 2 March 2016
Week 7
This week I'm going to talk about recursion once more, mainly because I'm finding it so fascinating, but this time as it is used to implement an ADT - particularly a Tree. A Tree is an Abstract Data Type that allows you to store information in nodes, each of which has as many as one "parent node" and zero or more "children". The concept is very similar to how a family tree works. Take some progenitor in your family history, say a great great grandmother. Since we are beginning with her she has no "parents", she is the first level on the Tree essentially, and we call this the root. From here the tree grows. Each child of your great great grandmother's are listed next, each one of them having her as their parent node, and these children constitute level two of the Tree. The Tree continues in this same way until it gets to the lowest (or highest, depending on your perspective) level; that is, until you reach a level of children that have no children.
Well, the only difference between this image and the ADT Tree we are working with is that the ADT does not have to store "people" (great great grandmothers, aunts and grandfathers, for example) in its nodes, but each node is just a placeholder for some kind of information that the user of the ADT has deemed relevant. We can do various things with Trees, such as tell how many levels it has (what its height is), how many children it has - we can even limit how many branches one parent is allowed to send off. That is, we can say that for any node on the Tree, that node cannot have more than 2 children.
The reason I like this ADT so much is mostly because I've been interested in puzzle solving lately and I see here potential for an easy, although perhaps ultimately inefficient, solution for an algorithm that can choose the shortest path from some point A to B in a maze full of lots of dead-ends or other, though longer, paths from A to B. It shouldn't be too hard to list all the possible paths one can take beginning from point A (letting A be your root) and to organize this information in a Tree that displays each unique path. From there you could look at which paths end at position B and of those you could see which has the fewest number of nodes and that would be the quickest path from A to B through the maze. I've already finished the lab for tomorrow and will be working on the extra problems during lab hours, and hopefully I'll have some time this weekend to create a few small mazes and write such an algorithm using Trees to find the shortest path from their start to end points.
Well, the only difference between this image and the ADT Tree we are working with is that the ADT does not have to store "people" (great great grandmothers, aunts and grandfathers, for example) in its nodes, but each node is just a placeholder for some kind of information that the user of the ADT has deemed relevant. We can do various things with Trees, such as tell how many levels it has (what its height is), how many children it has - we can even limit how many branches one parent is allowed to send off. That is, we can say that for any node on the Tree, that node cannot have more than 2 children.
The reason I like this ADT so much is mostly because I've been interested in puzzle solving lately and I see here potential for an easy, although perhaps ultimately inefficient, solution for an algorithm that can choose the shortest path from some point A to B in a maze full of lots of dead-ends or other, though longer, paths from A to B. It shouldn't be too hard to list all the possible paths one can take beginning from point A (letting A be your root) and to organize this information in a Tree that displays each unique path. From there you could look at which paths end at position B and of those you could see which has the fewest number of nodes and that would be the quickest path from A to B through the maze. I've already finished the lab for tomorrow and will be working on the extra problems during lab hours, and hopefully I'll have some time this weekend to create a few small mazes and write such an algorithm using Trees to find the shortest path from their start to end points.
Subscribe to:
Posts (Atom)