introduction to trees
TRANSCRIPT
Introduction to TreesLecture 16
1107186 – Estrutura de Dados – Turma 02
Prof. Christian Azambuja PagotCI / UFPB
Universidade Federal da ParaíbaCentro de Informática
What is a Tree?
In graph theory, a tree is defined as a●
connected
Example:
acyclic graph.●
Node4
However, one suchgraph may generate
different treedata structures!
2
Edge1 5
3 6
2Universidade Federal da ParaíbaCentro de Informática
What is a Tree?
In graph theory, a tree is defined as aRoot node
●
connected
Example:
acyclic graph.●
4
4
12
1 5 2 5
4
3 6 3
3Universidade Federal da ParaíbaCentro de Informática
What is a Tree?
In graph theory, a tree is defined as a●
connected
Example:
acyclic graph.Root node●
14
2
25 641 5
33 6
4Universidade Federal da ParaíbaCentro de Informática
Definitions
Path Length●
Number of edges on a path.–1
Depth of a Node●
Equal to the path length to the root.–
83 72Height of a Node●
Equal to the path length from thenode to its deepest descendant.
Height of a Tree
–
4 9●
Equal to the height of the root.–
5 6
5Universidade Federal da ParaíbaCentro de Informática
Definitions
Child Node●
Each node canchild nodes.
Parent Node
have n 1–
● 83 72
It is unique fornode.
The root does parent node.
each–
4 9
not have–
5 6
6Universidade Federal da ParaíbaCentro de Informática
Definitions
Leaf Node●
Has no child node.– 1
Siblings●
Nodes with the same parent.– 83 72
Ancestors●
All nodes on the path to the root.–4 9
Descendants of a node n●
All nodes that share n as anancestor.
–5 6
7Universidade Federal da ParaíbaCentro de Informática
Definitions
Subtree●
Tree formed by a node 1–
and all its descendants.
83 72
4 9
5 6
8Universidade Federal da ParaíbaCentro de Informática