@not_implemented_for('directed')
def algebraic_connectivity(G, weight='weight', normalized=False, tol=1e-08, method='tracemin_pcg'):
    "Return the algebraic connectivity of an undirected graph.\n\n    The algebraic connectivity of a connected undirected graph is the second\n    smallest eigenvalue of its Laplacian matrix.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        An undirected graph.\n\n    weight : object, optional (default: None)\n        The data key used to determine the weight of each edge. If None, then\n        each edge has unit weight.\n\n    normalized : bool, optional (default: False)\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float, optional (default: 1e-8)\n        Tolerance of relative residual in eigenvalue computation.\n\n    method : string, optional (default: 'tracemin_pcg')\n        Method of eigenvalue computation. It must be one of the tracemin\n        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)\n        or 'lobpcg' (LOBPCG).\n\n        The TraceMIN algorithm uses a linear system solver. The following\n        values allow specifying the solver to be used.\n\n        =============== ========================================\n        Value           Solver\n        =============== ========================================\n        'tracemin_pcg'  Preconditioned conjugate gradient method\n        'tracemin_chol' Cholesky factorization\n        'tracemin_lu'   LU factorization\n        =============== ========================================\n\n    Returns\n    -------\n    algebraic_connectivity : float\n        Algebraic connectivity.\n\n    Raises\n    ------\n    NetworkXNotImplemented\n        If G is directed.\n\n    NetworkXError\n        If G has less than two nodes.\n\n    Notes\n    -----\n    Edge weights are interpreted by their absolute values. For MultiGraph's,\n    weights of parallel edges are summed. Zero-weighted edges are ignored.\n\n    To use Cholesky factorization in the TraceMIN algorithm, the\n    :samp:`scikits.sparse` package must be installed.\n\n    See Also\n    --------\n    laplacian_matrix\n    "
    if (len(G) < 2):
        raise nx.NetworkXError('graph has less than two nodes.')
    G = _preprocess_graph(G, weight)
    if (not nx.is_connected(G)):
        return 0.0
    L = nx.laplacian_matrix(G)
    if (L.shape[0] == 2):
        return ((2.0 * L[(0, 0)]) if (not normalized) else 2.0)
    find_fiedler = _get_fiedler_func(method)
    x = (None if (method != 'lobpcg') else _rcm_estimate(G, G))
    (sigma, fiedler) = find_fiedler(L, x, normalized, tol)
    return sigma
Return the algebraic connectivity of an undirected graph.

The algebraic connectivity of a connected undirected graph is the second
smallest eigenvalue of its Laplacian matrix.

Parameters
----------
G : NetworkX graph
    An undirected graph.

weight : object, optional (default: None)
    The data key used to determine the weight of each edge. If None, then
    each edge has unit weight.

normalized : bool, optional (default: False)
    Whether the normalized Laplacian matrix is used.

tol : float, optional (default: 1e-8)
    Tolerance of relative residual in eigenvalue computation.

method : string, optional (default: 'tracemin_pcg')
    Method of eigenvalue computation. It must be one of the tracemin
    options shown below (TraceMIN), 'lanczos' (Lanczos iteration)
    or 'lobpcg' (LOBPCG).

    The TraceMIN algorithm uses a linear system solver. The following
    values allow specifying the solver to be used.

    =============== ========================================
    Value           Solver
    =============== ========================================
    'tracemin_pcg'  Preconditioned conjugate gradient method
    'tracemin_chol' Cholesky factorization
    'tracemin_lu'   LU factorization
    =============== ========================================

Returns
-------
algebraic_connectivity : float
    Algebraic connectivity.

Raises
------
NetworkXNotImplemented
    If G is directed.

NetworkXError
    If G has less than two nodes.

Notes
-----
Edge weights are interpreted by their absolute values. For MultiGraph's,
weights of parallel edges are summed. Zero-weighted edges are ignored.

To use Cholesky factorization in the TraceMIN algorithm, the
:samp:`scikits.sparse` package must be installed.

See Also
--------
laplacian_matrix
@not_implemented_for('directed')
def algebraic_connectivity(G, weight='weight', normalized=False, tol=1e-08, method='tracemin_pcg'):
    "Return the algebraic connectivity of an undirected graph.\n\n    The algebraic connectivity of a connected undirected graph is the second\n    smallest eigenvalue of its Laplacian matrix.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        An undirected graph.\n\n    weight : object, optional (default: None)\n        The data key used to determine the weight of each edge. If None, then\n        each edge has unit weight.\n\n    normalized : bool, optional (default: False)\n        Whether the normalized Laplacian matrix is used.\n\n    tol : float, optional (default: 1e-8)\n        Tolerance of relative residual in eigenvalue computation.\n\n    method : string, optional (default: 'tracemin_pcg')\n        Method of eigenvalue computation. It must be one of the tracemin\n        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)\n        or 'lobpcg' (LOBPCG).\n\n        The TraceMIN algorithm uses a linear system solver. The following\n        values allow specifying the solver to be used.\n\n        =============== ========================================\n        Value           Solver\n        =============== ========================================\n        'tracemin_pcg'  Preconditioned conjugate gradient method\n        'tracemin_chol' Cholesky factorization\n        'tracemin_lu'   LU factorization\n        =============== ========================================\n\n    Returns\n    -------\n    algebraic_connectivity : float\n        Algebraic connectivity.\n\n    Raises\n    ------\n    NetworkXNotImplemented\n        If G is directed.\n\n    NetworkXError\n        If G has less than two nodes.\n\n    Notes\n    -----\n    Edge weights are interpreted by their absolute values. For MultiGraph's,\n    weights of parallel edges are summed. Zero-weighted edges are ignored.\n\n    To use Cholesky factorization in the TraceMIN algorithm, the\n    :samp:`scikits.sparse` package must be installed.\n\n    See Also\n    --------\n    laplacian_matrix\n    "
    if (len(G) < 2):
        raise nx.NetworkXError('graph has less than two nodes.')
    G = _preprocess_graph(G, weight)
    if (not nx.is_connected(G)):
        return 0.0
    L = nx.laplacian_matrix(G)
    if (L.shape[0] == 2):
        return ((2.0 * L[(0, 0)]) if (not normalized) else 2.0)
    find_fiedler = _get_fiedler_func(method)
    x = (None if (method != 'lobpcg') else _rcm_estimate(G, G))
    (sigma, fiedler) = find_fiedler(L, x, normalized, tol)
    return sigma