Trees
- A tree is a connected acyclic graph.
- A forrest is a collection of trees.
- For a tree |E| = |V| -1
- This is necessairy, but not sufficient
- Unless the graph is connected
- For every two vertexes in a tree, there is exactaly one path connecting them.
- In a tree, a vertex is frequently denoted as the root
- Applications of trees
- For every node in a tree, except for the root, there is a parent
- If there is a path p = (u,v) and u is the parent of v, then v is the child of u
- If there is a path p1 = (u,v) and a path2 (u,w). the v and w are siblings
- If there is a path p=(u,a, ...n, v), then u,a, ...n are proper ancestors of v and a, .. n, v are proper descendants of u.
- u is a descendant and an ancestor of u.
- If u is the parent of v, then v forms a subtree, which includes v and all of v's descendants.
- The depth of a vertex is the length of the simple path from the root to that vertex.
- The root has depth 0
- Children of the root have depth 1
- The height of a tree is the length of the longest path from the root to any node.
- If a vertex has a child then it is an internal vertex
- If a vertex has no children then it is a leaf
Binary Trees
- A binary tree is a tree where each vertex has no more than two children.
- If h is the height of a tree T={V,E}, n=|V|, then ⌊ lg(n) ⌋ ≤ h ≤ n-1
- These are refered to as the left child and the right child
- The left child is the root of the left subtree
- A binary search tree is a binary tree with the binary search tree property.
- The binary search tree property requires that for any tree or subtree all data in the left sub tree has a value smaller than the value of the root and that the value of any data in the right sub tree is larger than the value of the root.
Tree Implementation