Learn / Trees

Intermediate 16 min

Trees

Binary trees, traversals, and binary search trees.

What you will learn

  • Define root, child, leaf
  • Walk in-order traversal
  • Understand BST ordering
python
class TreeNode:
    def __init__(self, val, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def inorder(node):
    if not node:
        return
    inorder(node.left)
    print(node.val)
    inorder(node.right)

Try it yourself

Write a function that returns the height of a binary tree.