Download presentation
Presentation is loading. Please wait.
Published byEvangeline Phelps Modified over 8 years ago
1
Trees
2
Trees: – A trunk from the roots – Divides into branches – Ends in leaves
3
Tree Strucures Collection of nodes connected by edges – Single root node with no parent Node Edge
4
Tree Strucures Collection of nodes connected by edges – Single root node (no parent) – Parent nodes point to 1+ child nodes – Children of a parent are siblings – Every non-root node has 1 parent
5
Trees? Which is a tree? A B C
6
Trees? Which is a tree? A B C
7
Tree Strucures Parents are interior nodes
8
Tree Strucures Nonparents are leaves
9
Tree Strucures Every node can be root of a subtree
10
Tree Strucures Single path from root to any node – Length = number of edges
11
Tree Strucures Single path from root to any node – Length = number of edges Node's depth = distance to root 3 2 1 0
12
Tree Strucures Single path from root to any node – Length = number of edges Node's height = longest path starting from it – Leaf = 0 height 0 1 2 3
13
Tree Strucures Tree as a whole: – Height = Depth = root's height = max depth of all leaves
14
Trees… Categorizations
15
Trees… Brackets
16
Trees… File systems
17
Trees… Image recognition
18
Trees… HTML documents Natural language Math expressions…
19
Expression Tree
20
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right)
21
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right)
22
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right)
23
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15
24
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 –
25
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 – 1
26
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 – 1
27
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 – 1 /
28
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 – 1 /
29
Tree Traversal Inorder Traversal Traverse(Node) If Null, return Traverse(Left) Print Self Traverse(Right) 15 – 1 / 7
30
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self
31
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self
32
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15
33
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15 1
34
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15 1 -
35
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15 1 -
36
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15 1 - 7
37
Tree Traversal PostOrder Traversal Traverse(Node) If Null, return Traverse(Left) Traverse(Right) Print Self 15 1 – 7 /
38
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) /
39
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / -
40
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15
41
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1
42
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1
43
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1
44
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1 7
45
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1 7
46
Tree Traversal PreOrder Traversal Traverse(Node) If Null, return Print Self Traverse(Left) Traverse(Right) / - 15 1 7
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.