Teaching graph theory is useful because it is a way to set up problems that computers can solve, so it helps to have an understanding of how the information of a graph will be represented in a computer.
Computers allow programmers to create arrays. An array is a list of data. As the programmer, I can type in "int Tree;", and the computer sets aside 100 memory locations of type "int" in a row that are called Tree, Tree, Tree, ... up to Tree. Computers and programmers are used to the idea of starting counting at zero instead of one, but the data structure for a binary tree is easiest if we ignore Tree and start the root of the tree at Tree. We then have the next level, the children of Tree at Tree and Tree, the children of tree are at Tree and Tree, the children of Tree at Tree and Tree, and on and on. This makes for a simple way in computers to find the children of a node and the parent of a node.
Take the position of a node on the list and multiply that number by two to get the left child, and add one more to the left child number to get the right child. For example, the children of Tree are at Tree and Tree.
Take the position of a node and divide by two to get the parent position. If the number is odd, ignore the ½ and just use the whole number that remains. (Note: because I asked for "int" memory locations, the computer is forced to ignore the ½ when dividing, so that makes life easy in this particular instance.)
The parent of Tree is Tree. The parent of Tree is Tree, whose parent is Tree, whose parent is Tree, whose parent is the root node Tree.
Let's look at the trees from last week and see how a computer would store the information. Whenever we get a node that that has no children, the location on the list should have a number that shows it is empty. On factor trees, we never use the number 0 as a factor, so 0 will be the number we use to show a position is empty.
Tree on the left:
Tree = 300
Tree = 30 || Tree = 10
Tree = 5 || Tree = 6 || Tree = 5 || Tree = 2
Tree = 0 || Tree = 0 || Tree = 3 || Tree = 2 || Tree = 0 ...
Tree on the right:
Tree = 300
Tree = 150 || Tree = 2
Tree = 15 || Tree = 10 || Tree = 0 || Tree = 0
Tree = 3 || Tree = 5 || Tree = 5 || Tree = 2 || Tree = 0 ...
The ellipsis in both lists indicates that all the entries are 0 for the entire rest of the list.
I know this will make sense to anyone who has programmed a computer. I'm not as sure if it makes sense to folks who have never done that task, which can be both enjoyable and frustrating. If you are in that second group, drop a note to tell me how much sense this makes.