Binary Trees & BSTs
Model anything with a hierarchy (folders, family trees, decisions) as nodes with children, and solve problems on it by letting each node ask its children.
After this lesson you will be able to
- Use the vocabulary of trees: root, parent, child, leaf, subtree, depth and height.
- Represent a binary tree with a node class and build one.
- Write and trace preorder, inorder, postorder and level-order traversals, and say when to use each.
- Solve tree problems with the “ask the left and right subtrees” recursion pattern.
- State the binary search tree rule, and use it to search, validate and find ancestors.
Before you start. Recursion I is essential, because nearly every tree algorithm is a short recursive function. BFS helps for level order.