Thursday, 31 March 2016

Week 11


This week I revisited my slog entry from week 5. It is very evident that I have improved on my visualizing skills. During week 5, I was not visualizing what was happening for class LinkedListNode and LinkedList. As a result, I was not seeing the bigger picture. I knew how to walk through the LinkedList, but I had troubles with inserting values into the LinkedList. Therefore, I believe I have developed my thinking in the way I look at classes. I have learned that it is important to visualize what the class does and to draw out what happens if possible. I never drew any visual pictures of classes before until we were introduced to trees. That was when I realized that it is very helpful to draw a visual picture of the classes.

In addition to realizing the importance of visualizing, my perception of what computer science is has developed in that I see more of how computer science is applied to real life situations. In CSC108, it was all about how to get the right output, but in CSC148, we learn how to build classes to take on certain characteristics. I remember not understanding the point of a linked list. However, now it makes much more sense, in that it takes up much less memory space, especially if we're thinking about a list containing a large amount of numbers.

Thanks for reading!

Saturday, 26 March 2016

Week 10


This week was tough for me. My term test 2 marks were a hard blow for me, and I was swamped with other work from other classes. I felt like I was falling behind everything. I was so confused with this week's lab, which is a shame considering I had been doing so well up till now. I found it hard to estimate of a function's run time is O(n2) or O(nlogn). I will definitely have to review this concept more before the final.

It was a close call for Assignment 2. I almost thought I wouldn't be able to finish it on time because I was stuck on implementing depth_first_solve and breadth_first_solve for a very long time. I eventually figured out how to solve breadth_first_solve by using the deque that was suggested by instructors. I then followed the general format of the levelorder_visit function we went over during the lecture on traversing general trees, as breadth_first_solve travels in levelorder. Once I implemented breadth_first_solve, I ran all of the puzzles to see if it worked and it did. But I found that the running time was very long. I then saw that people were saying to use sets on Piazza. At first I wasn't sure how to use them as I kept getting a message saying I cannot add an unhashable type. I realized that class PuzzleNode was not immutable, so I switched to using the string of each puzzle contained within each node. This increased my running time by a significant amount, much to my surprise.

After implementing breadth_first_solve, I was once again stuck in a rut with depth_first_solve. I wanted to use recursion, since it seemed easiest in my mind. But the problem was that my function would only recursively travel through one branch of the tree and stop. I did not know how to fix that problem. Thankfully, I read a pseudocode online that used a queue like breadth_first_solve, and then everything made sense to me. I didn't realize that I could also use a queue like in breadth_first_solve, but all I needed to change was the way I added each PuzzleNode into the queue. In breadth_first_solve, after visiting a node, I added all of its children/extensions to the back of the queue. Then in depth_first_solve, I added all of the children/extensions to the front of the queue. I still can't believe that was all that needed to be changed between the two functions! Fortunately, I finished the assignment with 35 minutes to spare. Now there are no more assignments to complete! Hurray!

Thanks for reading!

Monday, 21 March 2016

Week 9


This week brought in the long-awaited second midterm. As my luck would have it, the TTC service was suspended from Sheppard all the way to Bloor-Yonge right at the time that I was taking it. As a result, I was late by 15 minutes. I was having a mental breakdown, and I wish I had more time but I guess that's life. But it's just frustrating that things like this happen at the most crucial moments -- especially since I performed poorly on the first midterm and this was my chance to redeem myself. I know I made a lot of stupid mistakes, because I keep forgetting that binary trees are different than regular trees, in that binary trees have a max arity of 2.

As for Assignment 2, I'm still stuck on how to implement the depth_first_solve and breadth_first_solve functions. I am having difficulties finding a way to link the PuzzleNodes together. It is very difficult, as the children parameter for class PuzzleNode is a list of PuzzleNodes, but each PuzzleNode should only have one child and they all link together until the arrival of the solved puzzle. I'm also not sure what happens when there are no more possible solutions, and how to stop the endless loop of extensions when that happens. Hopefully I'll be able to finish Assignment 2 soon, as I have a lot of big projects due soon from other classes.

See you next week!

Sunday, 13 March 2016

Week 8


This week was the final week before our second midterm and I am feeling more and more anxious about it! I really want to redeem myself but I am still not confident in my skills. I find the concept of binary trees and traversals confusing so I have some reviewing to do. However, I do feel confident about the concepts of the general tree, as I worked through all the functions/methods in the additional exercises of this week's lab. The only thing I had difficulties with was the levelorder_visit function. But after Professor Danny Heap went over the levelorder_visit function for binary trees, I knew how to implement the function for the general Tree class.

I spent the majority of this week working on Assignment 2. I've worked out most of my code for the puzzles, but I am stumped on how to implement the depth_first_solve and breadth_first_solve functions. I think the problem is that I don't quite understand how to utilize the PuzzleNode class. There is a puzzle parameter and a children parameter, which I understand, but I don't know what the purpose of the parent parameter is. I'm also confused why the parent parameter is behind the children parameter. At the moment, all I'm sure is that the depth_first_solve function travels through the puzzle tree in preorder, while breadth_first_solve travels in level order.

I would say the week ended off on a good note with the lab. I found it very easy, which I hope means that I have been improving on my recursion skills. I'm also very happy with my Assignment 1 mark, so hopefully things will only get better from here on out.

See you next week and good luck to everyone on the midterm!

Thursday, 3 March 2016

Week 7: Recursion

This week was all about recursion. My problem with recursion is that I spend too much time thinking about how to implement the recursive calls. I hope I can improve upon my speed, as I need to think fast for the upcoming midterm. Speed has always been my weakness. Both in high school and since coming to university, finishing tests under a time constraint has been a struggle. But practise makes perfect, and I will redeem myself!

I worked on the lab exercises this week. I found it very easy to write the first base condition, where it does not involve recursive calls. But the else block was confusing because I did not know how to incorporate the recursive calls. I found myself just writing the code like it was not recursive. I had the biggest difficulty with the function, max_length. The problem for me was to find a way to accumulate all the lengths of the sublists (if there was any) and return the max. I kept getting an error saying that you cannot find the length of an int and that was when I realized I had to make sure to find the length of the element I am iterating over only if it is a list.

The examples from the lectures have helped me a lot. I make sure to go over each example by myself after the lectures and write them out on paper. This allows me to make sure I understand what is going on. Moreover, tracing the code by writing them out also helps a great deal in understanding each step. I was particularly confused with the nested_contains function we went over in class because of the way it used the any method. The solution worked out in class was:

return any([nested_contains(x, value)
                if isinstance(x, list) else x == value
                for x in list_])

By tracing the code using the given docstring examples, I was able to understand how this code works. It iterates over each element in list_, as well as the elements of any sublists. When the element is not a list, it checks to see if the element equals the given value. If it does, it returns True. The any method then sees that there is a True, so it also returns True. After understanding this example, I felt a little more confident in my knowledge in recursion.