Tree Representations Mathematical structure An edge A leaf The root A node
Tree Representations The number of edges = number of nodes - 1
Tree Representations The number of edges = number of nodes – 1 Let T(n) be the number of edges in tree with n nodes True for the case of 1 node T(1) = 0
Tree Representations The number of edges = number of nodes - 1 Suppose it's true for k nodes T(k) = k-1
Tree Representations The number of edges = number of nodes - 1 Then adding a node also adds an edge T(k+1) = T(k)+1 = k
Tree Representations If (always) a tree of fewer nodes is made a child of the root of a larger tree, then no tree will have a height greater than or equal to h unless it has at least 2 h nodes.
Tree Representations If (always) a tree of fewer nodes is made a child of the root of a larger tree, then no tree will have a height greater than or equal to h unless it has at least 2 h nodes. For h=0, number of nodes is 1 so hypothesis is true
Tree Representations If (always) a tree of fewer nodes is made a child of the root of a larger tree, then no tree will have a height greater than or equal to h unless it has at least 2 h nodes. For h>0, suppose true, then T obtained from tree of height h-1 and tree of fewer nodes than that one. By hypothesis, number of nodes of first is ≥ 2 h-1, of second ≥ 2 h-1 so total ≥ 2 h. height h-1, # nodes ≥ 2 h-1 T T 1 2 height h, # nodes ≥ 2 h-1 because this is the larger tree.
Tree Representations Matrix representation: rows indexed on nodes, columns also
Tree Representations Adjacency list representation: 0 : : : : :... Could be implemented with arrays or with linked lists
Tree Representations Binary tree representation: 3 tail root NULL 4 rghtnext leftnext 34 NULL 14 NULL 5 lefttree rghttree