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.
Sunday, 29 March 2015
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.
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.
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.
Subscribe to:
Posts (Atom)