Chapter 8: Trees. 25 sections.
25 items
Trees are usually introduced with drawings: circles connected by lines, one circle at the top, several below it, then more below those.
Depth-first search (DFS) is the fundamental traversal technique for trees.
Breadth-first search (BFS) visits a tree level by level.
Most tree algorithms are recursive, not because recursion is elegant, but because trees are recursive objects.
Tree height measures how far a tree extends downward from a node.
The diameter of a tree is the length of the longest path between any two nodes.
The Lowest Common Ancestor (LCA) of two nodes is the deepest node that is an ancestor of both.
Many tree algorithms repeatedly ask the same question: > What is the ancestor of this node k levels above?
Many tree problems become dramatically easier when you stop thinking of the tree as a tree.
Many tree problems ask questions about an entire subtree rather than an individual node.
Many tree algorithms compute information relative to a fixed root.
Many search problems involve prefixes.
Many tree algorithms eventually become range-query problems.
Not every range-query problem requires the full power of a Segment Tree.
Segment Trees provide efficient range queries and point updates.
Most data structures answer questions about the present.
Many tree problems ask questions about paths.
Many tree algorithms process information from a fixed root.
All previous tree algorithms in this chapter assume that the tree structure is fixed.
Two trees may look different at first glance yet represent exactly the same structure.
A tree in memory is not directly portable.
Most tree representations focus on speed.
Expression trees represent computations as tree structures.
Suppose two computers each store a copy of a large dataset.
This chapter has introduced a wide range of tree algorithms and data structures.