Sunday, 29 March 2015

Go Back to Binary Tree and Recursion

On week 7, I wrote a slog about binary tree and recursion. Now I revisit it and I still agree my thinking at that time. It is true that binary tree gives us a relatively simple way to search a particular element compared to other trees. Maybe I should change "simple" to "efficient" because we learned about efficiency on last week and I think "efficient" is the better word to describe its attribute. Although searching time still depends on the number of elements or nodes(n) a binary tree has, it literally halves the n every time after it finished a comparison. We use lg(n+1) to represent the maximum times to search n nodes.  lg(n+1) is same as log2(n+1). It becomes much smaller than n when n is getting larger. I've learned this in calculus.
Now let's talk about recursion. I feel more comfortable about recursion. I practiced a lot before the second term test. It was not difficult after several times of memorizing. Time I spend practicing is proportional to how fast and how well I write recursive program.

Tuesday, 24 March 2015

Week 10

On week 10, we discussed the second assignment. Our professor showed us one minimax solution. It was not so complicated. First, it generates all the game states reachable in one move. Then it finds score by recursion. Finally, it returns -1 times the lowest score. The minimax my group wrote was very similar to that one  and it worked perfectly. However, efficiency was something we needed our minimax to improve. One way to improve the efficiency was to reduce unnecessary call. For example in the game subtract square, if the program already found all available moves for a number once, we can save the result into a dictionary so it needs not to repeat the same process when that number appears again.  We will make it happen on next assignment.

Sunday, 15 March 2015

Test 2

On week 9, there was not much new stuff we learned because we had the second term test on Wednesday. On Monday, our professor wrote a function called delete. This function consists several  if statements because it works for binary tree and comparison is required. I personally think this function is advanced. The reason is it took me a long time to just understand the code. In the first look, I was so confused because I couldn't figure out how this function deletes node. It seemed no variable was assigned by new data. But eventually it found the hidden code, it was below the  "else" and new data was from a helper function. That helper function is recursive.
I hope I can learn how to write it shortly.

Linked List

On week 8, linked list were introduced. It is a liner sequence of nodes. This means each node can only connect one node. We also learned two terms - front and back. Front represents the whole linked list and back represents the last node. It seemed to be easier than tree. However, when we started to build some functions like delete_back or append, there were several variables we need to change. For example, front, back, and size should be changed in the function delete_back.
To draw a picture before writing codes is helpful because sometimes people cannot visualize linked list in their heads very well. Instead, if we draw a picture, it would be clear that which variable is going to change and how it would change.

Friday, 27 February 2015

Binary Tree

On week 7, professor Denny introduced binary tree. Each node in binary tree has two subtrees (left subtree and right subtree), or no subtree. Moreover, binary tree can represent a binary arithmetic expression because of its property. The definition of binary tree is that data in left subtree are always then than node's data. Similarly, data in the right is bigger than node's data. This gives us a relatively simple way to search. Sometimes we can avoid checking each subtree by comparing data. This saves us a lot of time.
I wrote some functions related to binary tree in this week's lab. All of them required recursion. It was not quite easy to write a recursion line because sometimes the idea was not very clear. It was even harder to express in form of code. To fully understand how to use recursion, I must practise a lot.

Wednesday, 3 December 2014

Countable and Uncountable

On week 9, we learned how to determine whether a set is countable or uncountable. A set is countable if and only if it is listable. For example, rational numbers are countable because they can be listed. Also, the number of elements that a countable set has is no larger than the size of natural numbers. Interesting enough, the size of even natural numbers is equal to the size of natural numbers.  However, the size of real numbers between 0 and 1 is beyond the size of natural number. No matter how you list them, I can find a number that does not appear on your list. This means that the real numbers between 0 and 1 are not listable, therefore they are uncountable.

Computable and Non-Computable

There was a fall break on week 11, so we had only 2 lectures on that week. We learned the difference between computable and non-computable. If f is a well-defined function and we cannot compute f(x), then f is non-computable. Otherwise it is computable. Also, we can use reduction to prove a function non-computable.