- 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
- Read Vaidehi Joshi's articles on depth-first search and breadth-first search with beautiful drawings and excellent analysis
- 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 tree traversal methods on the
BinarySearchTree
class 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.py
to testBinarySearchTree
traversal methods on a small example - Run
pytest binarytree_test.py
to run the binary tree unit tests and fix any failures
- Implement iterative tree traversal methods on the
BinarySearchTree
class (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
TreeMap
class (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 whetherkey
is in the tree mapget(key)
- return the value associated withkey
in the tree map, or raiseKeyError
if not foundset(key, value)
- insertkey
(or update, if already present) with associatedvalue
in the tree mapdelete(key)
- deletekey
and associated value from the tree map, or raiseKeyError
if not found
- Write unit tests to ensure the
TreeMap
class 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
TreeMap
class to those of theHashTable
class and the Pythondict
type