Thursday, November 28, 2013

Week #12

Last official week of the semester! We talked about memoization and dynamic programming. Memoization is a technique to avoid redundant calls in functions. It's top down while dynamic programming is bottom up. We also talked about sorting functions again. Selection sort is more efficient than bubble sort. One strategy for sorting is to divide and conquer. Merge sort uses recursion that continually splits a list in half. It is an O(nlogn) algorithm. With tail call optimization, quick sort's efficiency can be increased. Quick sort also used the divide and conquer method. It is an O(n^2) algorithm.

This semester went by so fast. It's less than a month away from Christmas! I don't think I tried my best so I have some regrets. I shouldn't forget this feeling and try my best next semester when most of my courses start with CSC...I should also make more use out of the help center and office hours. I went to some of them but I got lazy and didn't bother asking for help. Now...time to start studying for the final (but I'll probably procrastinate again).

Week #11 - Term Test #2

I got my second test back. I did A LOT better on this time compared to the last test. Maybe because there were less questions. I talked to another classmate at the office hours and he made the same mistakes as I did. We both counted the same interior node twice and forgot to use n.value instead of n. If I used tuple unpacking for the first question, my code would've been simpler. One of the benefits of using tuple is that you don't need a temporary variable to swap values. You can just do this: b, a = a, b in Python. Tuples are immutable so they can be used as keys in a dictionary like strings. On the second question, I got one mark off for not using n.value. I should always remember that n refers to the node and if I want the value I should use n.value. I'm happy I did better on this test. I hope I do well on the final and increase my mark!

Week #10

YAY FALL BREAK. Only two days off...then test on Wednesday. I'm so glad we get to bring a cheat sheet to the test. Writing one helps me study too. Remember to always have the base case in recursion! (ex. what will happen for an empty tree) The first element in preorder is the root of the tree. The last element in postorder is the root. The first element in inorder is the most left element in the tree. It helps to draw the basic tree of what the question is asking. Cargo can be any type but the left and right should be tree nodes when you're building a tree. At first I didn't understand that and just gave values to left and right. But even if the tree is very simple with only 3 elements, you should make left and right tree nodes with None as their left and right. I hope I do well on the test...

Week #9

This week talked more about Big-O. We can compare performance of algorithms by observing its behaviour over a large input. From best to worst: constant (c), logarithmic (clogn), linear (cn), quadratic (cn^2), cubic (cn^3), exponential (c2^n), and the worst case (cn^n or cn!). Big-O is the upper-bound so the previous listed times are part of each other. We talked about sorting too. There are many different kinds of sorting and there are also good sorting methods and inefficient sorting methods. Some of the sorting kinds are selection, quick, and merge.

In lab 8, we had to write an inorder traversal and longest path functions. It was hard to make the LLNode not list all its parent nodes when I just wanted the current node. Some people are so good at coding. They finish a lot faster than I do. I get discouraged, then I remember what I read sometime ago. "You can't be the best. There always will be someone who is smarter than you." I think this is supposed to make me feel better and motivate me to try my best. Not sure if it does that or just make want to give up.

Thursday, November 7, 2013

Week #8

Having done CSC165 already in the summer, I learned about Big-O and measuring algorithm performance. But it's not like I completely understand it now. I think it's a very complex topic. Another thing we learned this week is the binary search tree. Its requirements are first, it's a binary tree, secondly, its left nodes contain smaller values than the current node, and finally, its right nodes contain larger values than the current node, provided the tree is balanced. This is convenient to computer scientists because we don't have to look through the whole tree. We can eliminate the other half if the node we're searching for is smaller or larger than the current node. In class, we learned how to insert and delete nodes.

Monday, October 28, 2013

Week #7: Midterm Review

I got my midterm back. Sadly, but not surprisingly, I didn't do well. I passed but I lost a lot of marks in the first question because I didn't know how to compare tuples. To get the minimum of tuples, you have to compare the first element to find the minimum and if there is more than one that is the same, you compare the second element. By doing it by hand and checking later on Wing, I got the answer. Question 2 I stil didn't get the answer. List comprehensions are hard... It makes sense in my head but the code doesn't want to work :( Last questionn I did okay. I forgot to set the return type as FunctionalList. It was as easy as putting my answer now in FunctionalList(...). Hope I will do better on my next assignments, exercises, and tests.

Monday, October 21, 2013

Week #6

TypeError: 'NoneType' object is not subscriptable

I was getting this error for e4b.py. In the end, I finally understood the recursive function was working by going through my code step by step. Something I learned in programming is a little single thing in your code makes a huge impact. NEVER OVERLOOK ANYTHING. Also it helps a lot to talk about it with someone else because as you're telling them the problem, you figure out the solution suddenly! It's the best feeling when you fix your code and it works. This is more satisfying to me than writing essays. I hope I do well on this exercise.