/**
 * Find spectral gap in the vector of eigen values, this will denote the best cut in the corresponding graph
 * @see spectral graph partitioning
 * @param {number[]} values
 * @returns {number}
 */
export function eigen_values_find_spectral_gap(values) {
    let largest_gap = Number.NEGATIVE_INFINITY;
    let largest_gap_index = -1;

    const n = values.length - 1;
    for (let i = 0; i < n; i++) {
        const v0 = values[i];
        const v1 = values[i + 1];

        const gap = Math.abs(v0 - v1);

        if (gap > largest_gap) {
            largest_gap = gap;
            largest_gap_index = i;
        }
    }

    return largest_gap_index;
}
