Week #11: Revisiting SLOG Week #7
It is nearly a month after writing Slog week 7. I have got a lot in this short month. New concepts include binary trees, binary search trees, linked structure, unittests, and assertions. Most of them are related to the simple Tree structure and recursion I talk about in that slog. I still insist that we use recursion for we want the computer to inherit
that instinct and what the function wants to do is just what the
programmers want to do. That is the only reason for us to trace the function and
use the function-- to do what the programmers want to do. But I have something new to mention in this slog.
First is avoiding the unnecessary steps in our recursion when we implement a binary search tree structure.
First is avoiding the unnecessary steps in our recursion when we implement a binary search tree structure.
Just like the function shown above, we can see that we need to compare the data parameter in the header with the node.data to help us decide whether using recursion to the left subtree or using recursion to the right subtree. As mention in Slog week 8, we can promote the efficiency of the recursion by
compare the requirement with the left nodes and right nodes, which results to a
faster searching speed. Also sometimes we need to focus on the order of the items we return, just like the example shown below.
As can be seen on the left, we can see the comparison between the node.data and the requirement which is used to restrict the recursion to a efficient situation. Also the item to be returned is in the order: left -> node -> right, this is also required highly concentration!
Furthermore, I want to talk something about the option B in Assignment 3. The whole assignment 3 is talking about how to avoid redundancy, i.e. avoid revisiting the same data node(not the same node) in the tree. From each game state, we can generate a tree structure representing the following next states until the end of the game. Then we may find that when we traverse the tree we will meet a node we have seen before. So why we calculate it again with the recursion? That means a waste of time and resources. We need to make our recursive function much more efficient by avoiding visiting some node we have seen before. But to do so is not that simple as we are talking here. We may need to build a large structure to remember what nodes we have met before. Just like we implement distinct_node_count, we need remember what node we have met and we will not need to visit the same node under the node we have seen before. Then we build a set() to store them. But what about the branching_stats, outcome_counts and etc.? It will be really hard to realize avoiding redundancy! We may need to build a much larger structure -- dictionary to store the game states as keys and results as values. That is really complicated and also waste of time. So maybe we can build a database to store all the results as values in a dictionary in the future?
Hence the redundancy and efficiency are key problems that we should focus on after the lectures and assignment this month.
This time I want to introduce http://148choi.blogspot.ca/2015/03/week-11-revisiting-earlier-slog-posting.html. Choi's slog is really long, so we need more patience to read it. And I think that he/she need to compose his/her article to make it much more readable. Despite of these, his/her words 'the tracing was actually “the calm before the storm” of the actual implementation of recursion' are quite interesting and similar to my assertions mentioned time by time in my previous slogs.
Also, http://juliansongcsc148slog.blogspot.ca/ Julian's slogs are full of details of her implementations and feelings of the course. I have a lot of details for sure, but sometimes I maybe want to hide my feeling for some reasons. Good slogs to study!
This time I want to introduce http://148choi.blogspot.ca/2015/03/week-11-revisiting-earlier-slog-posting.html. Choi's slog is really long, so we need more patience to read it. And I think that he/she need to compose his/her article to make it much more readable. Despite of these, his/her words 'the tracing was actually “the calm before the storm” of the actual implementation of recursion' are quite interesting and similar to my assertions mentioned time by time in my previous slogs.
Also, http://juliansongcsc148slog.blogspot.ca/ Julian's slogs are full of details of her implementations and feelings of the course. I have a lot of details for sure, but sometimes I maybe want to hide my feeling for some reasons. Good slogs to study!
No comments:
Post a Comment