def collect_ids_recursive(root):
    """
    Return a list of ids of all leaves of the given tree
    """
    if root.is_leaf():
        return [root.id]
    return collect_ids_recursive(root.left) + collect_ids_recursive(root.right)