- Tree iteration = tree traversal
- Unlike lists, many natural orderings
- Level Order
- Traverse top-to-bottom, left-to-right
- Nodes "visited" in given order
-
Depth First Traversals
- Preorder (root, left, right), Inorder (left, root, right), Postorder (left, right, root)
- Level Order Traversal
-
Iterative Deepening
-
Runtime
$$\Theta(N)$$ b/c each new level doubles amount of work done & # of nodes visited- Exponential in height of tree,
$$\Theta(2^{H})$$ → height logarithmic in # of nodes,$$H = \Theta(\log{N})$$ → overall runtime linear in # of nodes,$$\Theta(N)$$
- Exponential in height of tree,
-
Spindly Runtime
$$\Theta(N^{2})$$ - Tree Height & Runtime
-
Runtime
-
Iterative Deepening
- Instead of traversing entire tree, only want to look at items in certain range
- Pruning: Restrict search to only nodes containing path(s) to answer(s)
- Runtime
- Generalization of BST
- Think of items as oriented in particular 2D direction (e.g NW/NE/SW/SE instead of binary </>)
- Can have mutliple different quadtrees for same set of data
- Just like BST, insertion order determines topology of QuadTree
- If on boundary line, usually assume = → >
- Pruning
- Analogous to binary search on BST (eliminate unnecessary search spaces)
- Ignore branches if no possible way branch could contain wanted item
- Use
Stackbased DFS traversal