|
| 1 | +## Class 10: Tree Traversals |
| 2 | + |
| 3 | +### Topics |
| 4 | +- [Tree traversal] |
| 5 | + - [Depth-first search]: pre-order, post-order, in-order traversal |
| 6 | + - [Breadth-first search]: level-order traversal |
| 7 | + |
| 8 | +### Resources |
| 9 | +- Review Make School's [tree traversal slides] |
| 10 | +- Watch Make School's [tree traversal video lecture] |
| 11 | +- Read Interview Cake's articles on [depth-first search][IC DFS], [breadth-first search][IC BFS], and [binary tree properties][IC binary tree] |
| 12 | +- Watch HackerRank's [trees and binary search tree video][HR trees video] (traversals start at 3:00) |
| 13 | +- Watch Harvards's [family trees and binary search tree video][Harvard trees video] and [stack frames video] |
| 14 | +- Play with VisuAlgo's [interactive binary search tree visualization][visualgo bst] |
| 15 | + |
| 16 | +### Challenges |
| 17 | +- Implement tree traversal methods on the `BinarySearchTree` class using [binary tree starter code]: |
| 18 | + - `_traverse_in_order_recursive` - traverse the tree with recursive in-order traversal (DFS) |
| 19 | + - `_traverse_pre_order_recursive` - traverse the tree with recursive pre-order traversal (DFS) |
| 20 | + - `_traverse_post_order_recursive` - traverse the tree with recursive post-order traversal (DFS) |
| 21 | + - `_traverse_level_order_iterative` - traverse the tree with iterative level-order traversal (BFS) |
| 22 | +- Annotate tree traversal methods with complexity analysis of running time and space (memory) |
| 23 | +- Run `python binarytree.py` to test `BinarySearchTree` traversal methods on a small example |
| 24 | +- Run `pytest binarytree_test.py` to run the [binary tree unit tests] and fix any failures |
| 25 | + |
| 26 | +### Stretch Challenges |
| 27 | +- Implement iterative tree traversal methods on the `BinarySearchTree` class (*without using recursion*): |
| 28 | + - `_traverse_in_order_iterative` - traverse the tree with iterative in-order traversal (DFS) |
| 29 | + - `_traverse_pre_order_iterative` - traverse the tree with iterative pre-order traversal (DFS) |
| 30 | + - `_traverse_post_order_iterative` - traverse the tree with iterative post-order traversal (DFS) |
| 31 | +- Annotate tree traversal methods with complexity analysis of running time and space (memory) |
| 32 | + |
| 33 | + |
| 34 | +[tree traversal]: https://en.wikipedia.org/wiki/Tree_traversal |
| 35 | +[depth-first search]: https://en.wikipedia.org/wiki/Depth-first_search |
| 36 | +[breadth-first search]: https://en.wikipedia.org/wiki/Breadth-first_search |
| 37 | + |
| 38 | +[tree traversal slides]: slides/TreeTraversals.pdf |
| 39 | +[tree traversal video lecture]: https://www.youtube.com/watch?v=Qd8dKFaRu9I |
| 40 | +[HR trees video]: https://www.youtube.com/watch?v=oSWTXtMglKE |
| 41 | +[HR bst interview problem]: https://www.youtube.com/watch?v=i_Q0v_Ct5lY |
| 42 | +[Harvard trees video]: https://www.youtube.com/watch?v=mFptHjTT3l8 |
| 43 | +[stack frames video]: https://www.youtube.com/watch?v=beqqGIdabrE |
| 44 | +[IC BFS]: https://www.interviewcake.com/concept/python/bfs |
| 45 | +[IC DFS]: https://www.interviewcake.com/concept/python/dfs |
| 46 | +[IC binary tree]: https://www.interviewcake.com/concept/python/binary-tree |
| 47 | +[visualgo bst]: https://visualgo.net/bst |
| 48 | + |
| 49 | +[binary tree starter code]: source/binarytree.py |
| 50 | +[binary tree unit tests]: source/binarytree_test.py |
0 commit comments