Solution
A tree organizes information so that it spreads out from a main point called the root node. Each piece of information is a node that can connect to other nodes, forming a branching structure. This is different from a list, where items sit one after another in a straight line.
A family tree is an example: the oldest ancestors are the root, and descendants form later levels. Parent-child relationships are not stored well in a linear list, so a tree is used.
Properties:
- Root Node: The first or top node, like the main folder that contains all other folders and files.
- Edges and Nodes: Nodes are the elements; edges are the lines that connect them. A node with no children is a leaf, like a file that contains no other files.
- Height: The longest path from the root down to the farthest leaf. It tells how deep or tall the tree is.
- Balanced Trees: The left and right branches are nearly the same height.
Trees are used for file-system backup (pre-order) and deletion (post-order), organisational charts, family trees, and decision trees.