Codele / Data structures
Trees
Some data is not a row or a pile but a family: things with parents and children. Pick a person and watch the way down from the oldest ancestor.
- A tree is data with parents and children, drawn with the parent above and the children below.
- The root is the one item with no parent. A leaf is an item with no children.
- Every item except the root has exactly one parent, so one list of “child: parent” describes the whole tree.
- To find the way from the root to an item, climb up by asking for each parent, then read the list from the root down.
- Depth is how many steps an item is below the root. The root has depth 0. Folders inside folders are a tree too.
Loading the playable lesson…