2025-10-29
Trees
nodes, with a single node designated as the root.predecessor and successor are replaced with parent and child| Term | Definition |
|---|---|
| Node | An item stored in a tree |
| Root | The topmost node in a tree (only node without a parent) |
| Child | A node immediately below and directly connected to a given node |
| Parent | A node immediately above and directly connected to a given node |
| Siblings | The children of a common parent |
| Leaf | A node that has no children |
| Interior node | A node that has at least one child |
| Edge/Branch/Link | The line that connects a parent to its child |
| Term | Definition |
|---|---|
| Descendant | A node’s children, its children’s children, and so on |
| Ancestor | A node’s parent, its parent’s parent, and so on |
| Path | The sequence of edges that connect a node and one of its descendants |
| Path length | The number of edges in a path |
| Depth or level | Equals the length of the path connecting it to the root |
| Height | The length of the longest path in the tree |
| Subtree | The tree formed by considering a node and all its descendants |
binary treesgeneral trees
D as directory (now folder) and F as fileN nodes and a height of N − 1
Height and the Number of Nodes in Full Binary Tree| Height (h) | Minimum Nodes | Maximum Nodes (Full Binary Tree) |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 2 | 3 |
| 2 | 3 | 7 |
| 3 | 4 | 15 |
| h | h + 1 | 2^(h+1) - 1 |
h, the maximum number of nodes is 2^(h+1) - 1.h is h + 1 (vine-like tree).Preorder traversal visits nodes in the following order:
Pseudocode:
Example:
For the tree below, the inorder traversal order is: A, B, C, D, E, F, G

Example:
For the tree below, the postorder traversal order is: A, C, B, E, G, F, D

Level order traversal visits nodes level by level from top to bottom and left to right within each level.
This traversal uses a queue data structure.
Pseudocode:
Example:
For the tree below, the level order traversal order is: D, B, F, A, C, E, G
