- Tree traversal
- Depth-first search: pre-order, post-order, in-order traversal
- Breadth-first search: level-order traversal
- Review Make School's tree traversal slides
- Watch Make School's tree traversal video lecture
- Read Interview Cake's articles on depth-first search, breadth-first search, and binary tree properties
- Watch HackerRank's trees and binary search tree video (traversals start at 3:00)
- Watch Harvards's family trees and binary search tree video and stack frames video
- Play with VisuAlgo's interactive binary search tree visualization
- Implement recursive tree search methods on the
BinarySearchTreeclass using binary tree starter code:_find_node_recursive(item)- return the node containingitemin the tree, orNoneif not found (hint: implement this first)_find_parent_node_recursive(item)- return the parent of the node containingitem(or the parent of whereitemwould be if inserted) in the tree, orNoneif the tree is empty or has only a root node
- Implement tree traversal methods on the
BinarySearchTreeclass using binary tree starter code:_traverse_in_order_recursive- traverse the tree with recursive in-order traversal (DFS)_traverse_pre_order_recursive- traverse the tree with recursive pre-order traversal (DFS)_traverse_post_order_recursive- traverse the tree with recursive post-order traversal (DFS)_traverse_level_order_iterative- traverse the tree with iterative level-order traversal (BFS)
- Annotate tree traversal methods with complexity analysis of running time and space (memory)
- Run
python binarytree.pyto testBinarySearchTreetraversal methods on a small example - Run
pytest binarytree_test.pyto run the binary tree unit tests and fix any failures
- Implement iterative tree traversal methods on the
BinarySearchTreeclass (without using recursion):_traverse_in_order_iterative- traverse the tree with iterative in-order traversal (DFS)_traverse_pre_order_iterative- traverse the tree with iterative pre-order traversal (DFS)_traverse_post_order_iterative- traverse the tree with iterative post-order traversal (DFS)
- Annotate tree traversal methods with complexity analysis of running time and space (memory)
- Implement
TreeMapclass (map/dictionary abstract data type implemented with binary search tree data structure) with the following properties and instance methods:__init__- initialize a new empty tree map structuresize- property that tracks the number of tree map entries in constant timekeys- return a list of all keys in the tree mapvalues- return a list of all values in the tree mapitems- return a list of all entries (key-value pairs) in the tree mapcontains(key)- return a boolean indicating whetherkeyis in the tree mapget(key)- return the value associated withkeyin the tree map, or raiseKeyErrorif not foundset(key, value)- insertkey(or update, if already present) with associatedvaluein the tree mapdelete(key)- deletekeyand associated value from the tree map, or raiseKeyErrorif not found
- Write unit tests to ensure the
TreeMapclass is robust (hint: these should be very similar to the hash table unit tests)- Include test cases for each class instance method
- Annotate class instance methods with complexity analysis of running time and space (memory)
- Compare the behaviors of your
TreeMapclass to those of theHashTableclass and the Pythondicttype