There are a few ways to represent a tree T with n nodes.
One particularly flexible way is in terms of three arrays. For
:
- Tv[i]: The key for node i.
- Tp[i]: The index of the parent of node i (-1 for root).
- Tl[i]: The index of the left child of node i (-1 if there is none).
- Tr[i]: The index of the right child of node i (-1 if there is none).
How can we test if node i is a leaf?
Next: HEAPS
Up: DYNAMIC PROBLEMS
Previous: Ordered Trees