Tuesday, April 7, 2015

Impression of week 8 --- Binary Tree

This week is about Binary Tree. It is a special case of a normal tree data structure in which each node has at most two children, which are referred to as the left child and the right child. This adds some degree of certainty since each node only have two direction to branch out, either left or right. And this is where a special case of Binary Tree comes into play --- Binary Search Tree. 

BST is essentially a sorted BT in which for every node,  the right child will stores a value that is greater than its parent node, and similarly the left contains a smaller value than its parent.  The purpose for such kind of layout is to increase efficiency. For instance, from the labs, we are able to to search the BST very efficiently since we could avoid visiting unnecessary nodes. 

This week's lab provides a great chance practicing recursion, we call the function on each level of node where we are tackling the same scenario: taking an advantage of the attribute of BST, we could decide which way do we keep recursing.  





impression of week 9 --- I did minimax incorrectly !!!

I should have written about assignment 2 sometime ago, but having a million of other things going on, I didn't even manage to finish it on time. I was stuck on minimax since 6pm on the due date(due 10pm), and I started debugging with my broken minimax till 10pm. Considering even though successfully fixed minimax would probably not give me 5 more marks, I didn't further my struggle after submitting my unfinished assignment 2 to mark us, and then totally forgot about it.

It was not until I saw Danny's code of Minimax on lecture today that I realized I didn't actually implement minimax correctly. Maybe it was due to my lack of understanding of the handout, maybe it's my laziness to seek for help from office hours or TA, maybe it was my own stupidity...but anyways, I was supposed to do minimax in such a way: find out all possible game over states and their scores, for all possible next moves from the original game state, transforming these scores in opponent's point of view and the move with the lowest score is my best move. This would make sure that if there is a move that guarantees a win, we will definitely choose it. Then I decided to redo my minimax.

What troubled me the most is that minimax only process score-move data bundle, and it would only return such a bundle as well, but our suggest_move should only return a Move object, I was stuck on that part for quite a while. The solution turned out to be very simple: use a helper function. We can let the helper function do all the work, and pass the returned bundle to suggest_move, which will extract the desired piece of information from the bundle.

Minimax greatly improve my understanding on recursion as well as many techniques and little hacks of recursion. Recursion is really a power tool, and it marks the milestone of introduction to Computer Science, instead of Programming!

Impression of the week 7 --- Linked Lists

This week we studied linked lists, which is similar to a ''unary'' (base one) Tree where each node has one or no child.  In linked list, each node is directed to the next node in a 'list' of nodes as well as its own value.  And the very first node of linked list is like the root node in a tree, which carries the entire structure, yet it only has direct reference to the next node.

What makes linked list special is its way of inserting new elements to the middle. In normal lists, each element has an index, if we want to insert new item into a certain position of the list, then we will have to move all the elements after that position one index forward to make space for the new item, which will involve lots of unnecessary steps. Where as in linked list, we simply make the two adjacent nodes in that position which used to reference each other, now reference to the new item inserted; and the rest are left untouched.   

However, we do need to loop through the linked list in order to find out the two node which we need to change their linkage according to the index where we desire to insert the item. But intuitively, the worst case of this is in O(n) while the conventional lists insertion is in O(n^2), where n is the length of the list. 

Wednesday, March 4, 2015

Object-Oriented Programming

As a 'transitioner' from csc108,  Object-Oriented Programming  seems really tedious and unnecessary to me at first. For the Subtract Square game in assignment one, I could totally make the game by just using a bunch of for loops, ifs and user inputs, without touching classes at all. And introducing classes makes the game structure much more complicated, thus much more bugs and errors to fix. 

It was not until assignment 2 that I started to realize the merit of OOP: with a clear and well-defined data structure, it actually prevents bugs and errors. Since as the game gets more complicated,  it's really easy to get lost if the gaming process are not well recorded. All those classes coded by the Professors, such as Game State and Game view provide us with the means to keep track of the entire game and AI's move. 


OOP is like designing the right tools before diving into the problem directly, it might seem a bit of wasting time at the beginning, nevertheless it will definitely offer long term benefits when things get harder. ''Well begun is half done'' Sometimes choosing the right way is more important than starting to deal with the problem right way. 

Tracing Recursion --- to be graded

Recursion is something I have never touched before, it is mind-blowing in a sense that it allows us to execute an arbitrary amount(i.e. just the right amount ) of commands according to the problem. Instead of tackling one specific case of the problem, recursion serves as a generic formula, whose power lies in the possibility of defining an infinite amount of objects with only a finite number of lines of codes. It is particularly mighty in a way that it automatically adjusts the amount of code needed to solve the problem. Human intelligence is embodied by the infinity achieved by 'finity'. 

Tracing is already confusing enough, yet it is only a piece of cake compare to actually writing your own recursion. It all started after the introduction of tree ; not only we have to tackle with the confusing enough tree structure, but also its entanglement with recursion.   At the beginning, I was more or less 'trying' to make the recursion work by keeping typing some random code similar to the example, instead of actually having the whole idea of knowing how to do this in my head. 

Well, "No pain No gain", "Pain is temporary, GPA is forever", although recursion really is really hurting my brain, but these are extremely good mental working out which will definitely benefit me in other aspects of life. Logic, persistence and resilience are the ever-lasting virtues, triumph will always belong to human's mind.      




Sunday, February 8, 2015

Why geeks need to know how to write?

We have entered a society in which science are predominantly embedded in various aspects of our life, ranging from a scissor to a smart phone. We have been unprecedentedly depend on technology ever before, which gives rise to the golden era of geeks: no matter it is a glitch of your home appliances or your forever crashing python program, geeks are always prepared with the complete knowledge base to save your life.

Geeks only spend their time on the very most practical skills among the pool of human knowledge(they are born to solve technical issues after all). It seems that they should be immune to all form of arts---literature, music, language, speech, etc., and sometimes not even the basic writing skill(they probably rarely have the mood to lay their bottom to a chair in their high school English class, and thus barely pass the literacy test)

Is this the mere outcome of natural selection and human functionality specialization? OF COURSE NOT!

Writing is actually a universal skill which lays the foundation of academic communication across a broad range of subjects, an idea is not substantiated until it is articulated by words, and preferably on a piece of paper due to its considerably better portability than voice. It would make no sense if an idea is trapped in one's owe mind instead of spreading it to the world and make a difference, no matter how brilliant this idea is.

For instance, in Python, a well written doc-string or comment will greatly facilitates  people to comprehend on your codes.  The competency of a programmer is never only a matter of how sophisticated a program he/she can writes, but most importantly, how easy your boss/clients can understand it.          

Sunday, February 1, 2015

My impression of the first feel weeks.

My impression of the first feel weeks.


I used to have this illusion that I should be able to breeze through 148 with the preparation from 108, it was not until the second week that I realized the level difficulty of this course was well disguised by the easy relaxing first week. I was sadly caught off guard by this course due to this sudden switch of teaching style from the '' handout spoon fed" in 108 to ''here are some example codes, go figure out the rest by yourself'' in 148. 

Nevertheless, I guess 148 is actually what is a typical university course like where instructors show but not tell, study is more on your own instead of being forced or obliged. Besides the knowledge and skills, I think responsibility, is the most important thing we will be learning through our 4 years university career, that there are some duty which are not forced upon us, yet we have to fulfill them at our best effort.

And personally I think tutorial labs are very beneficial, this is something we didn't have back in csc108, where most people get the chance to practice what they learned merely by doing the assignments. Whereas in csc148, there is an incentive for students to come to labs since there will be a quiz relates to the lab practice.