private int findMax(DegreeIndicator[] dis, boolean[] search_space) {
        if (dis.length != search_space.length) {
            throw new IllegalArgumentException("Degree indicators length does not match the search space");
        }

        int max = 0;

        // find the first eligible one
        while (max < dis.length) {
            if (search_space[max] == true) break;
            max++;
        }

        if (max == dis.length) {
            return -1; // not found first one
        }

        // continue to find the max one
        for (int i = max; i < dis.length; i++) {
            if (search_space[i] == true && dis[max].compareTo(dis[i]) > 0) {
                max = i;
            }
        }

        return max;
    }