def elimination_order_width(G, order):
    """Calculates the width of the tree decomposition induced by a
    variable elimination order.

    Parameters
    ----------
    G : NetworkX graph
        The graph on which to compute the width of the tree decomposition.

    order : list
        The elimination order. Must be a list of all of the variables
        in G.

    Returns
    -------
    treewidth : int
        The width of the tree decomposition induced by  order.

    Examples
    --------
    This example computes the width of the tree decomposition for the :math:`K_4`
    complete graph induced by an elimination order found through the min-width
    heuristic.

    >>> import dwave_networkx as dnx
    >>> import networkx as nx
    >>> K_4 = nx.complete_graph(4)
    >>> dnx.min_width_heuristic(K_4)
    (3, [1, 2, 0, 3])
    >>> dnx.elimination_order_width(K_4, [1, 2, 0, 3])
    3


    """
    # we need only deal with the adjacency structure of G. We will also
    # be manipulating it directly so let's go ahead and make a new one
    adj = {v: set(G[v]) for v in G}

    treewidth = 0

    for v in order:

        # get the degree of the eliminated variable
        try:
            dv = len(adj[v])
        except KeyError:
            raise ValueError('{} is in order but not in G'.format(v))

        # the treewidth is the max of the current treewidth and the degree
        if dv > treewidth:
            treewidth = dv

        # eliminate v by making it simplicial (acts on adj in place)
        _elim_adj(adj, v)

    # if adj is not empty, then order did not include all of the nodes in G.
    if adj:
        raise ValueError('not all nodes in G were in order')

    return treewidth
Calculates the width of the tree decomposition induced by a
    variable elimination order.

    Parameters
    ----------
    G : NetworkX graph
        The graph on which to compute the width of the tree decomposition.

    order : list
        The elimination order. Must be a list of all of the variables
        in G.

    Returns
    -------
    treewidth : int
        The width of the tree decomposition induced by  order.

    Examples
    --------
    This example computes the width of the tree decomposition for the :math:`K_4`
    complete graph induced by an elimination order found through the min-width
    heuristic.

    >>> import dwave_networkx as dnx
    >>> import networkx as nx
    >>> K_4 = nx.complete_graph(4)
    >>> dnx.min_width_heuristic(K_4)
    (3, [1, 2, 0, 3])
    >>> dnx.elimination_order_width(K_4, [1, 2, 0, 3])
    3