In CSC148, we have started learning about Trees which are another ADT. To be quite honest, for me Trees are a bit difficult to understand, especially since a lot of the functions that Trees use have a lot of recursion in it and there is also a lot of terminology that are associated with trees. When we first started talking about them, professor Heap talked about what a Tree contains, such as nodes, children nodes, edges, root, leafs, height, depth, etc. and it is actually quite overwhelming.
Okay so what exactly is a Tree? So from all that terminology, a Tree is a set of nodes with directed edges between nodes. The root note or the parent node starts at the top, and all the other nodes that "branch" out from the root note are called children. The nodes that have children are called inner nodes while nodes that have no children are called leafs. Take a look at this example,
A is the root note with directed edges towards children nodes B and C. Node B which is an inner node also has children nodes D, E, and F. Nodes C, D, E, and F are all leafs because they have no children. The height and depth of node A is 3 and 0, while the height and depth at node F is 0 and 3.
What can we do with Trees? Well in Assignment 2, we are kind of using Trees to build all the possible moves for our games. I say "kind of" because we will see it as a Tree but its really going to be a bunch of lists. The reason we are using Trees is for the minimax strategy which takes a look at all the possible moves and chooses the best moves in order to win. Our job is to create that Tree and put together all the successive moves one after another and check which move would make the player win.
How are Trees implemented? So far we have covered over how to look into Trees, and basically we have implemented functions to check whether or not values are contained in Trees and whether or how many leaves there are. For A2, we will want to implement functions that will build a Tree where nodes branch off to all the next possible moves.
A friend of mine, in one of his slog posts, he posted a pretty funny picture of a Christmas tree in the shape of a Tree. In his post he also covers a little of what I talked about here as well. Go check it out here: http://timothylock.ca/sLOG/CSC148/?p=80
As I said earlier, I am not too comfortable with Trees and just thinking about how I will create a Tree that contains all the possible moves is just quite overwhelming. I guess I'll just need to practice more. Though thanks for reading!
What can we do with Trees? Well in Assignment 2, we are kind of using Trees to build all the possible moves for our games. I say "kind of" because we will see it as a Tree but its really going to be a bunch of lists. The reason we are using Trees is for the minimax strategy which takes a look at all the possible moves and chooses the best moves in order to win. Our job is to create that Tree and put together all the successive moves one after another and check which move would make the player win.
How are Trees implemented? So far we have covered over how to look into Trees, and basically we have implemented functions to check whether or not values are contained in Trees and whether or how many leaves there are. For A2, we will want to implement functions that will build a Tree where nodes branch off to all the next possible moves.
A friend of mine, in one of his slog posts, he posted a pretty funny picture of a Christmas tree in the shape of a Tree. In his post he also covers a little of what I talked about here as well. Go check it out here: http://timothylock.ca/sLOG/CSC148/?p=80
As I said earlier, I am not too comfortable with Trees and just thinking about how I will create a Tree that contains all the possible moves is just quite overwhelming. I guess I'll just need to practice more. Though thanks for reading!
