Tree Review
Objectives
We would like to :- Review concepts associated with tree data structures.
Notes
- A tree is a directed graph
- With one node known as the root.
- Every node except the root has exactly one parent, or node pointing to it.
- The root node has no parents.
- Any node may have 0 or more children.
- Nodes with no children are known as leaf nodes.
- The height of a tree is the the longest path from the root to any node.
- A tree with only a root has height 0.
- A tree with a root with one child has height 1.
- The level of a node is the distance from the root to that node (or number of links).
- A complete tree is a tree where every level, except for the last, is full.
- This makes sense when we limit the number of children a node can have.
- A binary tree is a tree where each node can have at most two children.
- A binary tree of height h will have at most 2h leaf notes.
By Induction: To Show: A binary tree of height h will have at most 2h leaf nodes Prove true from the base case: A binary tree of height 0 at most 2h leaf nodes. Since a binary tree of height 0 has only one node, the root, which is also a leaf node, there are at most 1 = 20 leaf nodes. Assume true for k > 0 A binary tree of height k has at most 2k leaf nodes. Prove true for k+1 We know that a binary tree of height k has at most 2k leaf nodes. If each of these nodes is given two children, the number of leaf nodes will be 2*2k = 2k+1