def METHOD_NAME(tree, ba, sym):
    """
    Insert symbol into a tree at the position described by the bitarray,
    creating nodes as necessary.
    """
    nd = tree
    for k in ba:
        prev = nd
        nd = nd.child[k]
        if hasattr(nd, 'symbol'):
            raise ValueError("ambiguity")
        if nd is None:
            nd = Node()
            prev.child[k] = nd
    if hasattr(nd, 'symbol') or nd.child[0] or nd.child[1]:
        raise ValueError("ambiguity")
    nd.symbol = sym