Thursday, March 31, 2016

WEEK 11, The big O efficiency

This week we talked about big-o, and preview methods for recursion sorting. Truth be told I welcome the challenge of sorting recursion, but the mathematical big-o definition got me confused for a while.

After hours of studying, I figured out the whole point is to find out about how efficient is an algorithm given input size of n, and we measure time complexity in the order of number of operations an algorithm uses in its worst-case and will demonstrate it using big_O. It ranges from O(n) to O(n^2), or even O(n^n), the bigger the O, the less efficient the code is. The key factor of efficiency in a code depends on how many loops, and functions are called. The trick I found, is to number how many "for","while" loops are there, and do the calculation accordingly.
One thing about big-o that really worth mentioning is that a trick about "exponential calculation". for example the following code :

def silly2(n):
     n = 17 * n**2 n = n + 3
     print("n is: {}.".format(n))
     if n > 1997: for i in range(n): print(‘so big!‘)
     elif n > 97: print(‘big!')
     else: print('not so big!')


It's easy to get confused by its n**2n calculation. In fact, the big-O for this function is only 1. Doesn't really matter how complicated is the calculation for n, as long as it's not a loop, nor a function called, it only runs once.

Saturday, March 26, 2016

Week 10, reflection of assignment 2

Truth be told, assignment 2 seems to be daunting at the first glance. I read through Soduku but nothing made sense... I realized what I needed here is something more than programming skill, but patience.

After sovling the fail_fast method in sodoku, my confidence grew exponentially as I started solving peg. The extension part of peg was actually easy after I had found all the cases. Then I moved on to MN PUZZLE, which was a lot similar to peg in terms of extentions, involving with the switch of numbers and positions. The word puzzle was the easist, after implementing its extension and fail_fast, I laid my hands on the most tantalizing part of the assignment - puzzle_tool.

Depth first search and breadth first search sounds drastically different in method, but largely similar in coding. After messing with them around 8 hours - I found the only difference, the only difference that is that the list containing puzzle_nodes pops differently with the first one and the last one.

It's so much fun.

Wednesday, March 23, 2016

WEEK 9 , pain of recursion

 This week has been hard. The difficulty of recursion is rocketing when It's involved with MEMORIZATION. I had such a hard time, trying to use a set to memorize all the resaults from a recursion, but somehow I got an unhashable error.
  I asked the TA about the question, somehow he humbled that we'll get to learn this at thrid year. Gotta leave the question unanswered for now.
  I learnt much from the assignment, especially the debuging parts. I found making sheet is quite useful when facing sheer amount of data.
  Gotta keep going,

Sunday, March 13, 2016

Week8, tree and binary tree

It fascinates me when we talked about new data structure. Tree and binary tree were introduced to us recently.

We started with the basic stuff, defining what kinda attributes should trees contain, like the data of the root node, and the branches nodes of its children. Then we talked about how to measure its height, the number of its leaf by using recursion. It's very abstract to me at first, how would we accumulate number by calling one function over and over again? The functionality blew my mind. Danny talked about the essence of recursion - the base case, and then a general case where recursion is to be used.

Binary tree and binary search tree are shortly introduced. Similar to the general tree, but binary tree has the limitation which only takes branches by two. This give it a great capability when sorting numbers in binary search tree - smaller number goes to left whereas bigger number goes to right of the tree node.



Wednesday, March 2, 2016

WEEK7 reflection

One and half month just flew away like a common night staying up for coding - fast, and meaningful. I'm tired, but I fell in love with Computer Science.

This is the world of magic - it's totally abstract but real. I still clearly recall when professor talked about abstract data types, he said, everything in this world is math, as it can be simulated in programming languages. Then we got to try to simulate a point, a rectangle, gradually to a cashier, register, and it's mind-blowing - we are simulating the world. But to do this, rigorous programming methods are needed - setting up class, defining attributes and parameters, and implementing user-defined classes. Truth to be told I hated writing doc strings for the most of the time, but now, with 0 error and 0 warning on my assignment one report, I start to appreciate it. It is those little things that make a difference. Doc strings also help us to collaborate with other people, providing information about the data types of parameters and function description.

It gets, even more, exciting when it comes to the recursion part. I was totally amazed when Danny showed us he can use one line code to do the whole numbers counting for a nested list. That's amazing. But I had a hard time to comprehend it - after all the one-line coding expression is a bit abstract, something like  <Expression 1> If <condition one> Else <Expression 2>. Also, we need to follow the rule of the base case and recurse the general case.

The way ahead of us is arduous and exciting, I can't wait to do the next assignment!

Tuesday, February 23, 2016

WEEK 6, assignment 1

Coming back from the trip to Mexico, I found myself short on time to finish assignment 1. I regretted that I didn't start it earlier.

The assignment is a bit long. it took me some time to read through the given API's, client code to figure out what our classes, methods and functions had to do once we implemented them. After implementing easier classes such as Rider, Driver, Container and Dispatcher came some more difficult ones which used the former classes. Event, Monitor and Simulation were easily the most difficult classes to implement because together they formed the end goal of the assignment: to run a simulation and report the statistics.
The hardest part of the assignment is to figure out the interplay between classes, as when they work as one, it's sort of tricky to find the problem of which.

Friday, February 12, 2016

WEEK 5 term test slaughter and double linked list

   This week has been tough. I thought I was doing really well in CSC148, walking in the exam centre with ass-kicking confidence yet I found myself hopelessly stranded in the test. I didn't even finish it, at all.
    I guess that's a sign of "I should be working harder I guess".

    The lab this week was fun. We talked about linkednodelist, a flexible data type. Also I was practising my one-line-coding skill for example to write if and else in only one line like : Statement 1 if Statement 2 Else. which is really cool.