Wednesday, 2 March 2016

Week 7

This week I'm going to talk about recursion once more, mainly because I'm finding it so fascinating, but this time as it is used to implement an ADT - particularly a Tree. A Tree is an Abstract Data Type that allows you to store information in nodes, each of which has as many as one "parent node" and zero or more "children". The concept is very similar to how a family tree works. Take some progenitor in your family history, say a great great grandmother. Since we are beginning with her she has no "parents", she is the first level on the Tree essentially, and we call this the root. From here the tree grows. Each child of your great great grandmother's are listed next, each one of them having her as their parent node, and these children constitute level two of the Tree. The Tree continues in this same way until it gets to the lowest (or highest, depending on your perspective) level; that is, until you reach a level of children that have no children.
Well, the only difference between this image and the ADT Tree we are working with is that the ADT does not have to store "people" (great great grandmothers, aunts and grandfathers, for example) in its nodes, but each node is just a placeholder for some kind of information that the user of the ADT has deemed relevant. We can do various things with Trees, such as tell how many levels it has (what its height is), how many children it has - we can even limit how many branches one parent is allowed to send off. That is, we can say that for any node on the Tree, that node cannot have more than 2 children.
The reason I like this ADT so much is mostly because I've been interested in puzzle solving lately and I see here potential for an easy, although perhaps ultimately inefficient, solution for an algorithm that can choose the shortest path from some point A to B in a maze full of lots of dead-ends or other, though longer, paths from A to B. It shouldn't be too hard to list all the possible paths one can take beginning from point A (letting A be your root) and to organize this information in a Tree that displays each unique path. From there you could look at which paths end at position B and of those you could see which has the fewest number of nodes and that would be the quickest path from A to B through the maze. I've already finished the lab for tomorrow and will be working on the extra problems during lab hours, and hopefully I'll have some time this weekend to create a few small mazes and write such an algorithm using Trees to find the shortest path from their start to end points.

No comments:

Post a Comment