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!

No comments:

Post a Comment