blog




  • Essay / Graph Theory - 1544

    Tree DefinitionsIf you already know what a binary tree is, but not a general tree, then be very careful, because binary trees are not just the special case of general trees of degree two. I'm using the definition of a tree from the textbook, but keep in mind that other definitions are possible.Definition. A tree consists of a (possibly empty) set of nodes. If it is not empty, it is made up of a distinguished node r called root and of zero or more non-empty subtrees T1, T2, …, Tk such that there exists an edge directed from r towards each of the roots of T1, T2, …, Tk.Definition. A forest is a group of trees. You can still create a tree from a forest by creating a new root node and making it the parent of the roots of all trees in the forest. Conversely, if you cut the root of a tree, what remains is a forest. I assume you are familiar with the terminology of binary trees, for example, parents, children, siblings, ancestors, descendants, grandparents, leaf nodes, internal nodes. nodes, external nodes, etc., so I won't repeat their definitions here. Since the definitions of height and depth can vary from book to book, I include their definitions here, using those in the textbook.Definition. A path from node n1 to node nk is a sequence of nodes n1, n2, …, nk such that ni is the parent of ni+1 for 1 ≤ i < k. The length of a path corresponds to the number of edges in the path and not the number of nodes. Because the edges of a tree are directed, all paths are "down," that is, toward the leaves and away from the root. The height of a node is the length of the longest path from the node to any of its descendants. Naturally, the longest path must end at a leaf node. The depth of a node is the length of the path from the root to the node. The root has depth 0. All leaf nodes have height 0. The height of a tree is the height of its root. The degree of a node is the number of children of the node. The degree of a tree is the maximum degree of the degrees of its nodes. The tree on the next page has a height of 3 and a degree 5.