Topics:
Resources:
- review Julia Geist's AVL tree slides with animations and examples
- read Julia Geist's AVL tree article with animations and code samples
- watch MIT's AVL tree video lecture
- play with VisuAlgo's interactive AVL tree visualization to follow rotations step-by-step
- play with USF's interactive AVL tree animations
- play with USF's interactive splay tree animations
Challenges:
- implement
AVLNode
class with the following properties and instance methods using Julia's AVL tree starter code:data
- the node's dataleft
- the node's left child, if anyright
- the node's right child, if anyparent
- the node's parent, if not the rootheight
- the node's height (the number of edges on the longest downward path to a descendant leaf node)update_height
- recalculate height based on left child's height and right child's heightbalance_factor
- return the difference between left child's height and right child's height
- implement
AVLTree
class usingAVLNode
objects with the following properties and instance methods using Julia's AVL 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 treeretrace_up(node)
- retrace the path fromnode
up to the tree's root and perform any rotations necessary to rebalancerotate_left(node)
- rotatenode
's right child sonode
becomes its left childrotate_right(node)
- rotatenode
's left child sonode
becomes its right childitems_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_avl_tree.py
to run Julia's AVL tree unit tests and fix any failures - annotate class instance methods with complexity analysis
Stretch Challenges:
- implement splay tree with insert and search operations
- annotate class instance methods with complexity analysis