Topics:
- k-ary tree (n-ary tree, m-way tree)
- trie (prefix tree, radix tree)
- self-balancing trees with multiple keys: 2-3 tree, B-tree
Resources:
- review Julia Geist's trie slides with animations and examples
- read Julia Geist's trie article with animations and code samples
- play with USF's interactive trie animations
- review Alex Dejeu's B-tree slides with examples and motivating context
- read Alex Dejeu's 2-3 tree article with animations and code samples
- watch MIT's 2-3 tree and B-tree video lecture
- play with USF's interactive B-tree animations
Challenges:
- implement
TwoThreeNodeclass with the following properties and instance methods using Alex's 2-3 tree starter code:data- the node's list of datachildren- the node's list of children, if anyparent- the node's parent, if not the rootadd_data(data)- insertdatain order in the node's list of datais_full- check if the node is full (has at least 3 data)has_space- check if the node has space (has only 1 datum)is_leaf- check if the node is a leaf (has no children)is_internal- check if the node is internal (has at least one child)
- implement
TwoThreeTreeclass usingTwoThreeNodeobjects with the following properties and instance methods using Alex's 2-3 tree starter code:root- the tree's root nodeis_empty- check if the tree is emptyinsert(data)- insert a new node withdatain order in the treesearch(data)- check if a node withdatais present in the treefind_node(data)- return the node whereitemis (or would be) in the tree, or Nonesplit_node(node)- splitnodeto promote its median element and follow the path up to the tree's root and perform any more splits necessaryitems_in_order- return a list of all items in the tree found using in-order traversalitems_level_order- return a list of all items in the tree found using level-order traversal
- run
pytest test_two_three_tree.pyto run Alex's 2-3 tree unit tests and fix any failures - annotate class instance methods with complexity analysis
Stretch Challenges:
- implement trie with insert and prefix search operations
- revisit phone call routing scenarios 3, 4, and 5 with trie
- annotate class instance methods with complexity analysis