1
Trees & Binary Trees
2
Definition
! A (rooted) tree is a structure defined
- n a finite set of nodes that either:
– Contains no nodes, or
– Contains a specially designated node called the “root” and k>=0 disjoint sets of nodes T1,…,Tk, where each Ti is a tree. T1,…,Tk are called the subtrees of the root.
! Ordered tree: order of subtrees
matters.
A B E F M L K D G J N C H I
3
Treeminology
(Tree Terminology)
! Internal nodes and leaf nodes ! Parent/child relationship ! Siblings: children of the same parent ! Ancestor/descendant relationship ! Degree of a node: number of children
A B E F M L K D G J N C H I
4
Treeminology
(Tree Terminology)
! Path: a sequence n1,…,nk of nodes, s.t.
ni is the parent of ni+1.
! Tree height: length (number of edges)
- f longest path from the root to a leaf
! Node depth: length of the path from
the root to the node
A B E F M L K D G J N C H I