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
TwoThreeNode
class 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)
- insertdata
in 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
TwoThreeTree
class usingTwoThreeNode
objects 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 withdata
in order in the treesearch(data)
- check if a node withdata
is present in the treefind_node(data)
- return the node whereitem
is (or would be) in the tree, or Nonesplit_node(node)
- splitnode
to 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.py
to 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