Trees
Trees - It represents a hierarchical nature of a structure in a graphical from.
- Elements or nodes, with each node linked to its successors.
- Top of a treet is called its root. The link node to its successors are called branches, edges, lines, or paths.
- Successors of a nore are called its child nodes or childre. The predecessor of a node is called parents.
- A tree is considered a binary tree if all its nodes have two child nodes at most.
- Each node in a tree has exactly one parent except for root node, which has no parent
- Nodes that have the same parent are siblings.
- A node that has no child nodes is a leaf node or external node.
- Nodes that have childer are known as internal nodes.
- A tree within a tree is considered a subtree.
- The level of a node is a measure of its distance from the root.
- The depth of the tree is its highest level.
- The degre is the number of childen nodes in a subtree.
Breadth-First or Level Order: Nodes are visited by level. 1, 2, 3, 4, 5.
Depth-First:
Inorder (Left, Root, Right): Start with the bottommost left subtree. Once the root in Level 0 is visited, proceed to the bottommost right subtree.
Preorder (Root, Left, Right): Start with the root level in level 0 then continue with the left subtree. 1, 2, 4, 5, 3
Postorder (Left, Right, Root): Start with the bottommost left subtree then proceed to the other subtrees. The root in Level 0 is the last node visited.