Concept
A binary search tree keeps every left descendant smaller and every right descendant larger than a node, so search, insert and delete walk one path of O(height). An inorder traversal yields sorted order.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Binary search trees doing its job.
def insert(node, value):
if node is None:
return Node(value)
if value < node.value:
node.left = insert(node.left, value)
else:
node.right = insert(node.right, value)
return node
def is_bst(node, lo=float("-inf"), hi=float("inf")):
if node is None: return True
return (lo < node.value < hi and is_bst(node.left, lo, node.value)
and is_bst(node.right, node.value, hi))Validating a BST by checking each node only against its direct children. A grandchild can violate the ordering while every parent-child pair looks fine; the check needs the bounds inherited from above.
Your roadmap puts these before Binary search trees, unless you already know them.
Once a session shows you understand Binary search trees, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Binary search trees.