Download presentation
Presentation is loading. Please wait.
Published byAnis Rice Modified over 8 years ago
1
Tree Representations Mathematical structure An edge A leaf The root A node
2
Tree Representations The number of edges = number of nodes - 1
3
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
4
Tree Representations The number of edges = number of nodes - 1 Suppose it's true for k nodes T(k) = k-1
5
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
6
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.
7
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
8
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.
9
Tree Representations Matrix representation: rows indexed on nodes, columns also 0 1 2 3 4 5 6 7 8 9 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 2 0 1 0 1 0 0 0 0 0 0 3...... 9 0 0 0 0 0 0 1 1 0 0
10
Tree Representations Adjacency list representation: 0 : 2 3 7 9 23 45 1 : 0 4 5 2 : 1 8 10 14 3 :...... 111:... Could be implemented with arrays or with linked lists
11
Tree Representations Binary tree representation: 3 tail root NULL 4 rghtnext leftnext 34 NULL 14 NULL 5 lefttree rghttree
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.