1 Introduction

In recent years, fairness in algorithmic problems has become a profoundly studied topic, particularly so in machine learning and related areas. Clustering problems are fundamental in unsupervised learning and optimization in general. In this work, we focus on graph-based data clustering, and therein on one of the most basic and best studied problems, Cluster Editing (also known as Correlation Clustering). The goal is to cluster the vertices into a set of disjoint cliques by (few) edge modifications, that is, edge deletions or insertions. In the context of fairness, each vertex belongs to a certain subgroup within a social network (e.g. gender or nationality) and the goal is to find a solution that guarantees some “fairness” with respect to the considered subgroups. Previous works (Ahmadi et al. 2020; Ahmadian et al. 2020; Friggstad and Mousavi 2021; Ahmadian and Negahbani 2023) mainly focus on “output-oriented” fairness, that is, the fairness is defined by looking at the resulting clusters, enforcing that within each cluster, the number of vertices of each group is proportional to the overall number of vertices of the group. This kind of fairness, while prudent in some scenarios, may be inapt in other contexts, e.g., political districting.

Our main conceptual contribution is to introduce a fairness concept that is not modeling the fairness of the resulting clusters, but rather the fairness of the clustering process. In our case, this means that each group should be affected by roughly the same (proportionally to its size) number of edge modifications. This is motivated as follows: The edge modifications cause some distortion of the true social network. If the distortion for one group is significantly higher than for the others, then this can lead to a systematic bias in any further analysis of the cluster graph. Hence, this distortion should be proportionally distributed among the groups in order not to yield wrong (biased) conclusions from the resulting clustering. Imagine a collaboration graph where vertices are researchers from different countries (see Fig. 1 for an example). The five modifications shown in Fig. 1b yield a solution where the number of blueand red vertices per cluster is well balanced; thus the transformation is fair in the “output-oriented” fairness setting. However, most modifications are incident to blue vertices. The resulting cluster graph might suggest that the researchers from the blue country are barely collaborating with each other but rather with researchers from the red country — this does not really reflect the ground truth. The modifications shown in Fig. 1c are more balanced between blue and red vertices.

To mitigate such possible bias as described above, we introduce a colored version of the well-studied NP-hard Cluster Editing problem, where now the criterion of having fair modification cost yields a process-oriented fairness concept. Our modification fairness for Cluster Editing aims at balanced average distortion among the groups and is similar in spirit to the socially fair variants of k-means and k-median (Abbasi et al. 2021; Ghadiri et al. 2021), where the maximum average (representation) cost of any group is minimized. Of course, fairness might come at a price, in that more edge modifications might be required to achieve modification-fair solutions and more computation time might be required to find these. We perform both a theoretical (algorithms and complexity) and an empirical study. In a nutshell, we show that our new problem Modification-Fair Cluster Editing seems computationally slightly harder than Cluster Editing, but our experimental studies also indicate that the “price of fairness” (that is, how many more edits are needed compared to the classic, “colorblind” case) is relatively low if one does not aim for perfect fairness.

Fig. 1
figure 1

An exemplary graph G with blue (dark) and red (light) vertices (a) and two transformations of G into a cluster graph (b), (c). Inserted edges are marked green (thick), deleted edges are green and dashed. (b) A transformation of minimum size with five modifications. Eight modifications are incident to blue, two modifications are incident to red, so the average number of modifications to blue (red) vertices is \(\nicefrac {8}{4}\) (\(\nicefrac {2}{5}\)), and the difference is \(\nicefrac {8}{5}\). (c) Another minimum-size transformation in which the modifications are more balanced between blue and red (difference \(\nicefrac {7}{10}\))

Related work. For a thorough review on fairness in the context of machine learning we refer to the survey by Mehrabi et al. (2022). Closest to our work in terms of the underlying clustering problem are studies on fair Correlation Clustering (Ahmadi et al. 2020; Ahmadian et al. 2020; Friggstad and Mousavi 2021; Ahmadian and Negahbani 2023). These works focus an output-oriented fairness, that is, proportionality of the clusters. Facing the \(\textrm{NP}\)-hardness of the problem, these works mainly study polynomial-time approximation algorithms (while we focus on exact solvability).

Chierichetti et al. (2017) were the first to study fairness in the context of clustering, studying k-median and k-center problems. The works by Abbasi et al. (2021) and Ghadiri et al. (2021) for k-means and k-median clustering are closest to our fairness concept. However, while their fairness measure minimizes the maximum average cost of any group, our fairness measure minimizes the difference between the costs of groups. There are numerous further recent works studying fairness for clustering problems (Ahmadian et al. 2020; Bandyapadhyay et al. 2021, 2022; Chakrabarty and Negahbani 2021; Mahabadi and Vakilian 2020; Vakilian and Yalçıner 2021). For a general account on classic Cluster Editing, we refer to the survey of Böcker and Baumbach (2013).

Our contributions. We introduce Modification-Fair Cluster Editing, reflecting a process-oriented fairness criterion in graph-based data clustering: instead of looking at the outcome, we consider the modification process that yields the clustering. Here we demand that the average number of modifications at a vertex is balanced among the groups (we focus on two groups). We parameterize our fairness constraint by the difference between these averages. For a formal definition of Modification-Fair Cluster Editing, we refer to the next paragraph. Table 1 gives an overview over our theoretical contributions to Modification-Fair Cluster Editing; the corresponding results are in Sect. 2.

Table 1 Our theoretical results for Modification-Fair Cluster Editing and its restrictions which allow only insertions (Completion) or deletions (Deletion). Here, we denote by n the number of vertices, by m the number of edges, by \(\delta\) the fairness constraint, by k the number of modifications, and by \(\mu\) the number of mono-colored modifications, i.e., the number of modifications between same-colored endpoints. \(^\dagger\) (even if only mono-colored modifications are allowed) \(^\ddagger\) (even if only one vertex is red)

Among other results, we show that Modification-Fair Cluster Editing remains \(\textrm{NP}\)-hard even if only edge insertions are allowed (in the classic, colorblind variant, this case is trivially polynomial-time). This requires proving a related number problem to be \(\textrm{NP}\)-hard, which is deferred to Sect. 3. Moreover, we show the \(\textrm{NP}\)-hardness of very restricted cases of the general editing version and provide conditional running time lower bounds. On the positive side, we devise a randomized polynomial-time algorithm for the case that one modifies constantly many mono-colored edges (edges whose both endpoints have the same color). Moreover, we show the problem to be fixed-parameter tractable with respect to the overall number of edge modifications. On the empirical side (Sect. 4), we demonstrate that while typically computationally hard(er) to find, “fair solutions” seem not much more expensive than conventional ones.

Problem definition and initial observations. Recall that a graph is a cluster graph if and only if each of its connected components is a clique, that is, a completely connected graph. The family of cluster graphs is also characterized as those graphs that do not contain a \(P_3\) (a path on three vertices) as an induced subgraph. In Cluster Editing, we are given a graph G and an integer \(k \in {\mathbb {N}}_0\), and we are asked whether there is an edge modification set \(S \subseteq \binom{V(G)}{2}\) of size at most k such that the graph \(G_S\) with vertex set \(V(G_S):=V(G)\) and edge set \(E(G_S) :=(E(G) {\setminus } S) \cup (S {\setminus } E(G))\) is a cluster graph. We say that S transforms G into \(G_S\).

In our setting, the vertices in G are colored either red or blue, i.e., \(V(G) = R \uplus B\). For an edge modification set \(S \subseteq \binom{V(G)}{2}\), we define \({{\,\mathrm{\#ed}\,}}_S(v):=|\{e\in S\mid v\in e\}|\) to be the number of edge modifications incident to a vertex v (that is, the degree of v in the modification graph, whose edge set is S). Then

$$\begin{aligned} \Delta _{\textrm{ed}}(S):=\left| \frac{\sum _{v\in R}{{\,\mathrm{\#ed}\,}}_S(v)}{|R|}-\frac{\sum _{v\in B}{{\,\mathrm{\#ed}\,}}_S(v)}{|B|}\right| \end{aligned}$$
(1)

is the difference of the average numbers of modifications at a red vertex and a blue vertex.

  • Input:A graph G with \(V(G) = R \uplus B\), \(k\in {\mathbb {N}}\), and \(\delta \in {\mathbb {Q}}^+\).

  • Question: Is there an edge modification set \(S\subseteq \binom{V(G)}{2}\) with \(|S|\le k\) and \(\Delta _{\textrm{ed}}(S) \le \delta\) that transforms G into a cluster graph?

Analogously, we define the variants Modification-Fair Cluster Completion and Modification-Fair Cluster Deletion in which S may only add edges (i.e., \(S \subseteq \binom{V(G)}{2} {\setminus } E(G)\)) and delete edges (i.e., \(S \subseteq E(G)\)), respectively.

We immediately observe some simple upper bounds on \(\Delta _{\textrm{ed}}\).

Observation 1

For every edge modification set S, the following upper bounds hold: (i) \(\Delta _{\textrm{ed}}(S) \le |S|\); (ii) \(\Delta _{\textrm{ed}}(S) \le |V(G)|-1\); (iii)\(\Delta _{\textrm{ed}}(S) \le \nicefrac {2|S|}{\min \{|R|,|B|\}}\).

Proof

The bounds (i) and (ii) are trivial upper bounds on the maximum and thus also average number of edge modifications at any vertex. Bound (iii) holds as \(\Delta _{\textrm{ed}}(S)\) is at most

$$\begin{aligned}{} & {} \max \left\{ \frac{\sum _{v \in R} {{\,\mathrm{\#ed}\,}}_S(v)}{|R|}, \frac{\sum _{v \in B} {{\,\mathrm{\#ed}\,}}_S(v)}{|B|} \right\} \\{} & {} \quad \le \max \left\{ \frac{2|S|}{|R|}, \frac{2|S|}{|B|} \right\} = \frac{2|S|}{\min \{|R|, |B|\}}. \end{aligned}$$

This bound is met when all endpoints of the modifications carry the less frequent color. \(\square\)

By Observation 1, if \(\delta \ge \min (k,|V|-1,\nicefrac {2k}{\min \{|R|,|B|\}})\), then Modification-Fair Cluster Editing is simply the standard, “colorblind”, Cluster Editing.

We remark that that our problem definition allows the modification-fair edge modification set to be a non-minimal edge modification set. If one seeks the most fair and minimal edge modification set (of size at most k), then this can simply be computed with the standard \(P_3\)-branching algorithm (Cai 1996) which enumerates all solutions of size at most k.

Parameterized Complexity. Finally, we recall some basic (parameterized) complexity concepts. A parameterized problem is fixed-parameter tractable if there exists an algorithm solving any instance (xp) (x is in the input instance and p is some parameter—in our case it will be the number k of edge modifications) in \(f(p)\cdot |x|^{{\mathcal {O}}(1)}\) time, where f is a computable function solely depending on p. The class XP contains all parameterized problems which can be solved in polynomial time if the parameter p is a constant, that is, in \(f(p)\cdot |x|^{g(p)}\) time. The Exponential Time Hypothesis (ETH) claims that the 3-SAT problem cannot be solved in subexponential time in the number n of variables of the Boolean input formula. That is, there exists a constant \(c > 0\) such that 3-SAT cannot be solved in \({\mathcal {O}}(2^{cn})\) time. The ETH is used to prove conditional running time lower bounds, for example, it is known that one cannot find a clique clique of size s in an n-vertex graph in \(\rho (s)\cdot n^{o(s)}\) time for any function \(\rho\), unless the ETH fails (Chen et al. 2006).

2 Modification fairness: complexity

We explore the algorithmic complexity of Modification-Fair Cluster Editing and compare it to its “colorblind” counterpart Cluster Editing and its restrictions which either only allow edge deletions (Cluster Deletion) or insertions (Cluster Completion).

First, we show that even restricted special cases of Modification-Fair Cluster Editing remain NP-hard. Notably, the corresponding polynomial-time many-one reductions also lead to ETH-based running time lower bounds.

Theorem 2

Modification-Fair Cluster Editing and Modification-Fair Cluster Deletion are \(\textrm{NP}\)-hard for any value of \(\delta \ge 0\) and solvable neither in \(2^{o(k)}\cdot |V(G)|^{{\mathcal {O}}(1)}\) nor in \(2^{o(|V(G)| + |E(G)|)}\) time unless the ETH fails. This also holds

  1. (i)

    if only mono-colored edge modifications are allowed or

  2. (ii)

    if there is only one red vertex.

Both cases use similar reductions, based on the following \(\textrm{NP}\)-hardness result by Komusiewicz and Uhlmann (2012) for standard Cluster Editing.

Proposition 3

((Komusiewicz and Uhlmann 2012)) Cluster Editing is \(\textrm{NP}\)-hard, and, assuming the ETH, is neither solvable in \(2^{o(k)}\cdot |V(G)|^{{\mathcal {O}}(1)}\), nor in \(2^{o(|V(G)|)}\), nor in \(2^{o(|E(G)|)}\) time, even if all of the following holds:

  1. (i)

    all modifications are deletions;

  2. (ii)

    every solution has size at least k;

  3. (iii)

    the graph has less than 2k vertices;

  4. (iv)

    the graph has maximum degree six (and also contains vertices of degree exactly six);

  5. (v)

    every solution deletes at most four edges incident to any vertex.

We now provide the construction for Theorem 2(i). While we construct an instance of Modification-Fair Cluster Editing in the following, we will later see that we can use the same construction for the Deletion variant.

Construction 1

(for Theorem 2(i)) Let \(I = (G, k)\) be an instance of Cluster Editing. We may assume that I has the properties listed in Proposition 3. We construct an instance \(I' = (G', k', \delta )\) of Modification-Fair Cluster Editing as follows. The graph \(G'\) contains a copy of G with all vertices colored blue. Additionally, \(G'\) contains 3k red vertices which form k disjoint \(P_3\)s, i.e., paths on three vertices. Moreover, we add \(\max \{|V(G)|, 3k\} - 3k\) isolated red vertices and \(\max \{|V(G)|, 3k\} - |V(G)|\) isolated blue vertices to \(G'\) resulting in that the number of red and blue vertices being equal. Finally, we set \(k' :=2k\) and \(\delta = 0\).Footnote 1

Let us prove the correctness of the above reduction.

Lemma 4

Given an instance \(I = (G, k)\) of Cluster Editing, Construction 1 returns an instance \(I' = (G', k', \delta )\) of Modification-Fair Cluster Editing such that I is a yes-instance if and only if \(I'\) is a yes-instance. Moreover, whenever \(I'\) is a yes-instance, there exists a solution which only deletes edges.

Proof

Assume first that I is a yes-instance. By Proposition 3(i) and (ii), we may assume that any solution for I requires exactly k edge deletions.

Then, deleting the corresponding k edges in \(G'\) and also one arbitrary edge of each red \(P_3\) in \(G'\) clearly yields a solution \(S'\) of size \(2k=k'\) with \(\Delta _{\textrm{ed}}(S')=0\le \delta\) (as \(G'\) contains the same number of red and blue vertices). Note that \(S'\) contains only edge deletions.

Conversely, let \((G', k', \delta )\) be a yes-instance. Note that every solution modifies at least one edge of each of the k red \(P_3\)s in \(G'\). As the \(P_3\)s are all pairwise vertex-disjoint, we may assume without loss of generality that every such modification is a deletion. Hence, at most k edge deletions are performed to transform the copy of G in \(G'\) into a cluster graph. \(\square\)

We now provide the construction for Theorem 2(ii). Again, we will later see that the construction also proves \(\textrm{NP}\)-hardness for the Deletion variant.

Construction 2

(for Theorem 2(ii)) Let \(I = (G, k)\) be an instance of Cluster Editing. We may assume that I has the properties listed in Proposition 3. We construct an instance \(I' = (G', k', \delta )\) of Modification-Fair Cluster Editing as follows. The graph \(G'\) contains a blue copy of G as well as one red vertex r which is adjacent to an arbitrary vertex x of degree six from G (this exists due to Proposition 3(iv)). We further add \(2k - |V(G)| + 1\) isolated blue vertices such that overall \(G'\) contains \(2k+1\) blue vertices. Note that \(2k - |V(G)| + 1 > 0\) due to Proposition 3(iii). Finally, we set \(k' :=k+1\) and \(\delta = 0\).Footnote 2

Again, let us prove the reduction to be correct.

Lemma 5

Given an instance \(I = (G, k)\) of Cluster Editing, Construction 2 returns an instance \(I' = (G', k', \delta )\) of Modification-Fair Cluster Editing such that I is a yes-instance if and only if \(I'\) is a yes-instance. Moreover, whenever \(I'\) is a yes-instance, there exists a solution which only deletes edges.

Proof

If (Gk) is a yes-instance with solution S, then \(S':=S\cup \{\{r,x\}\}\) yields a solution for \(G'\) of size \(k+1=k'\) with \(\Delta _{\textrm{ed}}(S')=|\frac{1}{1} - \frac{2k+1}{2k+1}|=0\le \delta\). As we may assume that S contains only edge deletions, we may assume the same for \(S'\).

Conversely, suppose that \((G',k',\delta )\) is a yes-instance with solution \(S'\). By Proposition 3(ii), any modification set that transforms G into a cluster graph contains at least k edge deletions, and each vertex in G is incident to at most 4 deletions. Hence, the same holds true for \(S'\) restricted to \(V(G') \setminus \{r\}\). In other words, there are at least \(k = k' - 1\) edge deletions in \(S'\) that are not incident to r and each vertex in V(G) is incident to at most 4 of them. We claim that \(\{r, x\} \in S'\). Suppose not. Then, for each of the \(P_3\)s induced by r, x, and any neighbor \(v \ne r\) of x, the solution must either delete \(\{v, x\}\) or by adding \(\{v, r\}\). If we add the edges \(\{v, r\}\) for more than one of these \(P_3\)s, then the remaining number of modifications we can add to the solution is less than k; this does not suffice to transform the remaining graph into a cluster graph. So, for at least five of the \(P_3\)s, we need to delete the corresponding edge \(\{v, x\}\). This however contradicts the fact that every vertex in V(G) is incident to at most 4 modifications within G. Therefore, \(\{r, x\} \in S'\), and the remaining k modifications in \(S'\) are within G; hence (Gk) is a yes-instance. \(\square\)

Theorem 2 now follows from Proposition 3,Lemmas 4 and 5, together with the following observation.

Observation 6

Constructions 1 and2 run in polynomial time. Moreover, for any instance \(I' = (G', k', \delta )\) returned by either construction, we have \(k' \in {\mathcal {O}}(k)\), \(|V(G')| \in {\mathcal {O}}(\max \{|V(G)|, k\})\), and \(|E(G')| \in {\mathcal {O}}(|E(G)| + k)\).

We remark that Theorem 2 (i) also holds if the maximum degree is six and the maximum number of edge modifications (or deletions) incident to each vertex is at most four. These are immediate consequences of properties (iv) and (v) of Proposition 3.

Surprisingly, Cluster Completion, which is trivially solvable in polynomial time, becomes \(\textrm{NP}\)-hard when enforcing fairness.

Theorem 7

Modification-Fair Cluster Completion is \(\textrm{NP}\)-hard for every constant \(\delta \ge 0\). This also holds if only mono-colored edge insertions are allowed.

The proof is based on a polynomial-time reduction from the following problem, which we will later prove to be \(\textrm{NP}\)-hard in Sect. 3 (Theorem 11).

  • Input: A cluster graph G and an integer \(k \in {\mathbb {N}}_0\).

  • Question: Can G be transformed into another cluster graph by adding exactly k edges?

Construction 3

(for Theorem 7) Let \(\delta \ge 0\) be an arbitrary constant and let \(I = (G, k)\) be an instance of Cluster Transformation by Edge Addition with \(n :=|V(G)|\) and \(m :=|E(G)|\). We assume without loss of generality that \(k \le \binom{n}{2} - m\) (otherwise I is a trivial no-instance), and that \(2(m-n-1)/n \ge \delta\) (otherwise, the size of the instance is bounded by \(\delta\), which is constant). We construct an instance \(I' = (G',k',\delta )\) with \(k':=2k+\lfloor \frac{\delta n}{2}\rfloor\) as follows. The graph \(G'\) contains a copy of G where every vertex is colored blue together with n red vertices which form an arbitrary connected graph with \(x :=\binom{n}{2} -k - \lfloor \frac{\delta n}{2}\rfloor\) edges. Note that this is possible as

$$\begin{aligned} x \ge \Bigl (\begin{array}{@{}c@{}}n\\ 2\end{array}\Bigr ) - \left( \Bigl (\begin{array}{@{}c@{}}n\\ 2\end{array}\Bigr )-m\right) - \left\lfloor \frac{ n \cdot 2(m-n-1)/n }{2} \right\rfloor \ge n-1. \end{aligned}$$

\(\square\)

Let us prove the correctness of the reduction.

Lemma 8

Given an instance \(I = (G, k)\) of Cluster Transformation by Edge Addition, Construction 3 returns an instance \(I' = (G', k', \delta )\) of Modification-Fair Cluster Completion such that I is a yes-instance if and only if \(I'\) is a yes-instance.

Proof

Assume that (Gk) is a yes-instance. Then, adding the corresponding k edges to the blue copy of G in \(G'\) and the \(k+\lfloor \frac{\delta n}{2}\rfloor\) missing edges to the red subgraph yields a cluster graph. This set \(S'\) of added edges satisfies

$$\begin{aligned} \Delta _{\textrm{ed}}(S') = \frac{2(k + \lfloor \frac{\delta n}{2}\rfloor )}{n} - \frac{2k}{n} \le \frac{2k + \delta n - 2k}{n} = \delta . \end{aligned}$$

Conversely, let \((G',k',\delta )\) be a yes-instance. By our problem definition, our corresponding solution \(S'\) of size \(k'\) contains the \(k_r :=k + \lfloor \frac{\delta n}{2} \rfloor\) missing edges of the red subgraph of \(G'\). Let \(k_b\) be the number of edges between blue vertices and \(k^*\) be the number of edges between a blue and a red vertex in \(S'\) and note that \(k_b + k^* = k\). As we have \(k_r\) (\(k_b\)) edges with two red (blue) endpoints and \(k^*\) edges with one endpoint of each color, we have

$$\begin{aligned} \Delta _{\textrm{ed}}(S')&= \frac{2k_r+k^*}{n} - \frac{2k_b + k^*}{n} = \frac{2(k_r - k_b)}{n} \\&= \frac{2(k+ \lfloor \frac{\delta n}{2} \rfloor - k_b)}{n} \\&\ge \frac{2(k-k_b) + \delta n - 1)}{n} = \delta + \frac{2 k^* - 1}{n}. \end{aligned}$$

As \(\Delta _{\textrm{ed}}(S') \le \delta\) we have that \(k^* \le 0\).

So \(k_b = k\) and \(S'\) contains k edges in the blue copy of G in \(G'\); thus (Gk) is a yes-instance. \(\square\)

As Construction 3 is clearly computable in polynomial time, Theorem 7 follows immediately from Lemma 8 and Theorem 11.

We observe from the intractability results so far that the hardness of Modification-Fair Cluster Editing is rooted in finding the right mono-colored edge modifications. Indeed, we can show that, if only \(\mu\) mono-colored edge modifications are allowed for constant \(\mu\), then there is a randomized polynomial-time algorithm for this problem. We will prove that this can be done by guessing the \(\mu _R\) and \(\mu _B\) modifications between red and between blue endpoints before reducing to the Budgeted Matching problem: Given a graph H with edge weights \(w :E(H) \rightarrow {\mathbb {Q}}^+\), edge cost \(c :E(H) \rightarrow {\mathbb {Q}}^+\), and weight and cost bounds \(W, C \in {\mathbb {Q}}^+\), the problem asks whether there is a matching \(M \subseteq E(H)\) with \(w(M) :=\sum _{e \in M} w(e) \ge W\) and \(c(M) :=\sum _{e \in M} c(e) \le C\). Recall that an edge set \(M \subseteq E(H)\) is a matching if no two edges in M share an endpoint. (Berger et al. 2011,Lem. 8) have shown that, if all edge weights and costs and the budget are polynomially bounded in the size of the input graph, Budgeted Matching can be reduced in polynomial time to the Exact Perfect Matching problem, in which, given an n-vertex graph in which some edges are red and an integer \(k \in {\mathbb {N}}_0\), the task is to decide whether there exists a matching of size n/2 that contains exactly k red edges. For Exact Perfect Matching, there is a randomized algorithm without false positives and error probability at most a given \(\varepsilon > 0\) with running time \(n^{{\mathcal {O}}(1)} \log 1/\varepsilon\) (Mulmuley et al. 1987). (Notably, it is unknown whether there exists a deterministic polynomial-time algorithm for the problem.) Due to the reduction by Berger et al. (2011), Budgeted Matching can be solved by a randomized algorithm with asymptotically the same running time bound and error probability as the one for Exact Perfect Matching.

Theorem 9

Let \(\varepsilon > 0\). Then there is a randomized algorithm without false positives and error probability at most \(\varepsilon\) that solves Modification-Fair Cluster Editing in \(n^{{\mathcal {O}}(\mu )}\log 1/\varepsilon\) time, where n is the number of vertices and \(\mu\) is the number of allowed mono-colored modifications.

Proof

Let \((G, k, \delta )\) with \(V(G) = R \uplus B\) be an instance of Modification-Fair Cluster Editing and assume without loss of generality that \(|R| \ge |B|\). We first guess the numbers \(\mu _R\) and \(\mu _B\) with \(\mu _R + \mu _B \le \mu\) and the mono-colored modification sets \(S_R \subseteq \binom{R}{2}\) and \(S_B \subseteq \binom{B}{2}\) of size \(\mu _R\) and \(\mu _B\). Let \(G^*\) be the graph obtained after applying the modifications in \(S_R\) and \(S_B\) to G. Note that \(G^*[R]\) and \(G^*[B]\) must be cluster graphs as we can only do bi-colored edge modifications from here on. Now, for any hypothetical bi-colored edge modification set \(S' \subseteq \binom{V(G)}{2} {\setminus } (\binom{R}{2} \cup \binom{B}{2} )\), we require

$$\begin{aligned} \Delta _{\textrm{ed}}(S_R \cup S_B \cup S') = \left|\frac{2\mu _R + |S'|}{|R|} - \frac{2\mu _B + |S'|}{|B|} \right|\le \delta , \end{aligned}$$

which is equivalent to requiring

$$\begin{aligned} -\delta \le \frac{2\mu _R + |S'|}{|R|} - \frac{2\mu _B + |S'|}{|B|} \le \delta . \end{aligned}$$

If \(|R| = |B|\), then adding bi-colored edges will have no effect on \(\Delta _{\textrm{ed}}(S_R \cup S_B \cup S')\); thus we assume that \(|R| > |B|\). Then, adding bi-colored edges will increase the average number of edits incident to B more than those incident to R. The above inequalities yield the following lower and upper bound on \(|S'|\):

$$\begin{aligned}&\alpha ' :=\frac{-\delta - (2\mu _R/|R| - 2\mu _B/|B|)}{1/|R| - 1/|B|} \le |S'|\\&\quad \le \frac{\delta - (2\mu _R/|R| - 2\mu _B/|B|)}{1/|R| - 1/|B|} =:\beta '. \end{aligned}$$

Note that \(\alpha '\) and \(\beta '\) may be negative and larger than \(k-\mu\); thus we may look for a bi-colored edge modification set of size at least \(\alpha :=\max \{0, \alpha '\}\) and at most \(\beta :=\min \{k-\mu , \beta '\}\).

Let \(R_1,\ldots ,R_r\) and \(B_1, \dots , B_b\) be the vertex sets of the clusters in \(G^*[R]\) and \(G^*[B]\), respectively. Since \(S'\) shall only contain bi-colored edges, a solution can never merge two blue or two red clusters into one. Thus, any solution either isolates a cluster, or merges it with exactly one cluster of the other color. This can be modeled as a matching in a complete bipartite graph H with vertices \(u_1,\ldots ,u_r\) on one side and \(v_1,\ldots ,v_b\) on the other side, where a matching edge indicates which clusters are merged. Clearly, every cluster editing solution for \(G^*\) with only bi-colored edits corresponds to a matching and vice versa. Let \(E'\subseteq E(G)\) be the edges between R and B and let \(E_{ij}\subseteq E'\) denote the edges between \(R_i\) and \(B_j\). For a given matching M in H, a solution must remove all edges in \(E'\) except for those in \(E_{ij}\) corresponding to a matching edge \(\{u_i, v_j\} \in M\). Further, for every matching edge \(\{u_i, v_j\}\), we must add all \(|R_i||B_j| - |E_{ij}|\) missing edges. Hence, the size of a bi-colored modification set \(S'\) corresponding to M is

$$\begin{aligned}{} & {} |E'|-\;\sum \limits _{{\{u_i,v_j\}\in M}}\;|E_{ij}|+ \;\sum \limits _{{\{u_i,v_j\}\in M}}\;(|R_i||B_j|-|E_{ij}|)\\{} & {} \quad = |E'| - \;\sum \limits _{{\{u_i, v_j\} \in M}} (2|E_{ij}| - |R_i||B_j|). \end{aligned}$$

Define \(w :E(H) \rightarrow {\mathbb {Q}}^+\) with \(w(\{u_i, v_j\}) :=(2|E_{ij}| - |R_i||B_j|)\). Then, a matching M of weight \(|E'| - \beta \le w(M) \le |E'| - \alpha\) corresponds to a bi-colored modification set \(S'\) such that \(S_R \cup S_B \cup S'\) transforms G into a cluster graph and \(\Delta _{\textrm{ed}}(S_R \cup S_B \cup S') \le \delta\). To this end, we solve an instance for Budgeted Matching with cost function \(c \equiv w\) and budgets \(W :=|E'| - \beta\) and \(C :=|E'| - \alpha\) using the reduction (Berger et al. 2011) and randomized algorithm (Mulmuley et al. 1987) mentioned above. The algorithm returns the desired matching M with probability at least \(1-\varepsilon\) if it exists, and reports no otherwise. In the former case, we return the modification set \(S_R \cup S_B \cup S'\) and thus correctly report yes with probability at least \(1-\varepsilon\). If the algorithm reports no for every possible guessed mono-colored edge modification set \(S_R \cup S_B\), then we report that there is no modification-fair modification set of size at most k. Let \(n :=|V(G)|\). As there are \(\binom{n}{2}^\mu \le n^{2\mu }\) guesses, for each of which we solve an instance of Budgeted Matching in \(|V(H)|^{{\mathcal {O}}(1)}\log 1/\varepsilon \subseteq n^{{\mathcal {O}}(1)}\log 1/\varepsilon\) time, the running time follows. \(\square\)

We leave open whether or not Modification-Fair Cluster Editing is fixed-parameter tractable when parameterized by the number \(\mu\) of mono-colored edge modifications. However, for the larger parameter k, the number of edge modifications, we are able to prove fixed-parameter tractability — we will prove this next. Our approach is as follows. We first run the well-known \(P_3\)-branching algorithm (Cai 1996) to enumerate cluster graphs. As the resulting solution need not be modification-fair, we may need to do further edge modifications. For this, we first apply polynomial-time data reduction rules which shrink the graph size to a polynomial in k, and then brute-force on the reduced graph.

Theorem 10

Modification-Fair Cluster Editing can be solved in \(2^{{\mathcal {O}}(k \log k)} \cdot (n+m)\) time on n-vertex, m-edge graphs.

Proof

Let \((G, k, \delta )\) be an instance of Modification-Fair Cluster Editing with \(V(G) = R \uplus B\). We first apply the standard \(P_3\)-branching algorithm for Cluster Editing to enumerate all minimal cluster edge modification sets S of size at most k in \({\mathcal {O}}(3^k (n+m))\) time (Cai 1996). For each S, we check whether \(\Delta _{\textrm{ed}}(S)\le \delta\). If not, then we try to extend S to a fair edge modification set. Clearly, each fair edge modification set of size at most k contains at least one of the enumerated edge modification sets. Note that in order to check later that our modification set is fair, we store the original numbers |B| and |R| of blue and red vertices in G.

For each S, we first apply the following three data reduction rules to the cluster graph \(G'\) obtained from S.

  1. 1.

    If there is a clique with more than \(k+1\) vertices, then delete it.

  2. 2.

    If there are more than 2k isolated vertices of the same color which have not been touched by S, then delete one of them.

  3. 3.

    Let \(2 \le s \le k+1\) and \(0\le t \le s\). If there are more than k cliques with s vertices, t of which are blue, and none of them are touched by S, then delete one of them.

Note that we keep all cliques with at most \(k+1\) in \(G'\) which contain an endpoint of an edge in S. Clearly, there are at most 2|S| such cliques.

For the correctness, note that modifying a clique with \(\ell \ge 2\) vertices requires at least \(\ell -1\) edge modifications. Hence, Rule 1 is correct. Clearly, k edge modifications can touch at most 2k vertices of any color, so Rule 2 is correct. Rule 3 is correct as we cannot touch more than k cliques of size at least two.

For exhaustive application of the data reduction rules, we count the number of cliques with the same numbers of blue and red vertices. As we added at most k edges to obtain \(G'\), we can apply the rules in \({\mathcal {O}}(n+m+k)\) time. After exhaustive application, the remaining graph contains \({\mathcal {O}}(k^2)\) vertices contained in cliques touched by S and \({\mathcal {O}}(k^3)\) vertices not touched by S.

Let \(W\subseteq V(G)\) be the vertices remaining after exhaustive application of the above data reduction rules. We now try all possible extensions \(S' \subseteq \binom{W}{2} \setminus S\) of size at most \(k-|S|\) and check whether the set \(S^* :=S \cup S'\) transforms G into a cluster graph and is fair, that is, \(\Delta _{\textrm{ed}}(S^*) \le \delta\). There are \({\mathcal {O}}(k^{6k})\) such extensions; the checking can be done in \({\mathcal {O}}(m+n+k)\) time each. The overall running time thus is \(2^{{\mathcal {O}}(k\log k)}\cdot (m+n)\). \(\square\)

Seeing this approach, one may ask why it cannot be adapted to prove fixed-parameter tractability for the number \(\mu\) of mono-colored edge edits. Of course, we can use the standard branching algorithm to enumerate all minimal solutions for G[R] and G[B] in \({\mathcal {O}}(3^\mu (n+m))\) time. However, we cannot apply the three data reduction rules, as we can differentiate between the clusters in G[R] and G[B] due to their incident bi-colored edges. Hence, it is not clear which clusters we can safely discard.

3 Transforming cluster graphs

This section is devoted to proving the NP-hardness of the above introduced Cluster Transformation by Edge Addition. Recall that in this problem we are given a cluster graph G and an integer \(k \in {\mathbb {N}}_0\), and we are asked to decide whether G can be transformed into another cluster graph by adding exactly k edges.

Theorem 11

Cluster Transformation by Edge Addition is \(\textrm{NP}\)-hard.

We devise a polynomial-time reduction from the Numerical 3D Matching problem introduced and proven to be strongly \(\textrm{NP}\)-hard by Garey and Johnson (1975). Herein, given positive integers t, \(a_1, \dots , a_n\), \(b_1, \dots , b_n\), and \(c_1, \dots , c_n\), one is asked whether there are bijections \(\alpha , \beta , \gamma :[ n ] \rightarrow [ n ]\) such that \(a_{\alpha (i)} + b_{\beta (i)} + c_{\gamma (i)}=t\) holds for each \(i \in [ n ]\).

On a high level, our reduction works as follows. We add a small clique for every \(a_i\), a medium-sized clique for every \(b_i\), and a large clique for every \(c_i\). Throughout this section, we will refer to the number of vertices in a clique as its size. By appropriate choice of our solution size k, we can ensure that every clique in the resulting cluster graph — our so-called solution graph \(G'\) with vertex set \(V(G') = V(G)\) and edge set \(E(G') = E(G) \cup S\) — is the result of merging one small, one medium, and one large clique. We finally show that if each cluster consists of cliques corresponding to elements \(a_i\), \(b_j\), and \(c_\ell\) such that their sum is equal to the target t, then the number of required edge additions is minimized. That is, if there is a cluster that does not hit this target, then the resulting solution adds more than k edges.

Construction 4

(for Theorem 11) Let \(I=(t, a_1, \dots , a_n, b_1, \dots , b_n,c_1, \dots , c_n)\), \(n\ge 3\), be an instance of Numerical 3D Matching. As this problem is strongly \(\textrm{NP}\)-hard, there exists a global constant \(d > 0\) such that Numerical 3D Matching is \(\textrm{NP}\)-hard even if \(a_i, b_i, c_i \le n^d\) for all \(i \in [ n ]\). We assume without loss of generality that \(t > a_i, b_i, c_i\) for all \(i \in [ n ]\) and that \(\sum _{i=1}^n (a_i + b_i + c_i) = n \cdot t\), as otherwise I is a trivial no-instance.

We construct an instance \(I'=(G, k)\) of Cluster Transformation by Edge Addition as follows. Let \(A :=n^{2d}\), let \(B :=n^{3d}\), and let \(C :=n^{7d}\). For \(i \in [ n ]\), we set \(a'_i :=a_i+A\), \(b'_i :=b_i+B\), \(c'_i :=c_i+C\), and add three cliques of size \(a'_i\), \(b'_i\), and \(c'_i\), respectively, to G. We refer to these cliques by their size \(a'_i\), \(b'_i\), \(c'_i\) and call them small, medium-sized, and large, respectively. For more convenient notation, let \(t' :=t + A + B + C\). Finally, set

$$\begin{aligned}k :=n\Bigl (\begin{array}{@{}c@{}}t'\\ 2\end{array}\Bigr )-|E(G)|= n\Bigl (\begin{array}{@{}c@{}}t'\\ 2\end{array}\Bigr )- \sum _{i=1}^n\Big (\Bigl (\begin{array}{@{}c@{}}a'_i\\ 2\end{array}\Bigr )+\Bigl (\begin{array}{@{}c@{}}b'_i\\ 2\end{array}\Bigr )+\Bigl (\begin{array}{@{}c@{}}c'_i\\ 2\end{array}\Bigr )\Big ). \end{aligned}$$

\(\square\)

Proving the forward direction of our reduction is straightforward.

Lemma 12

If Construction 4 is given a yes-instance I of Numerical 3D Matching, then it returns a yes-instance \(I'\) of Cluster Transformation by Edge Addition.

Proof

Let \(\alpha , \beta , \gamma\) be a solution for instance I. Creating n clusters by merging the cliques \(a'_{\alpha (i)}\), \(b'_{\beta (i)}\), \(c'_{\gamma (i)}\) for each \(i \in [ n ]\) yields a solution graph \(G'\) with

$$\begin{aligned} |E(G')|&= \sum _{i=1}^n \Bigl (\begin{array}{@{}c@{}}a'_{\alpha (i)} + b'_{\beta (i)} + c'_{\gamma (i)}\\ 2\end{array}\Bigr ) \\&= \sum _{i=1}^n \Bigl (\begin{array}{@{}c@{}}t+A+B+C\\ 2\end{array}\Bigr ) = \sum _{i=1}^n \Bigl (\begin{array}{@{}c@{}}t'\\ 2\end{array}\Bigr ) \end{aligned}$$

edges, created by adding \(|E(G')|-|E(G)| = k\) edges. \(\square\)

The backward direction is more involved. In the following, let \(I' = (G, k)\) be an instance of Cluster Transformation by Edge Addition obtained from applying Construction 4 on an instance I of Numerical 3D Matching. We will first provide a lower and an upper bound on k. Then, step by step, we will prove that every solution of our constructed instance \(I'\) transforms our graph into a cluster graph with n cliques, each containing exactly one small, one medium-sized, and one large clique.

Lemma 13

In the constructed instance \(I'\) we have \(n(AC+BC) \le k \le 2nBC\).

Proof

It is easy to verify that for \(x_1, \dots , x_n \in {\mathbb {N}}\),

$$\begin{aligned} \left( {\begin{array}{c}\sum _{i=1}^n x_i\\ 2\end{array}}\right)&= \frac{1}{2} \bigg ( \Big ( \sum _{i=1}^n x_i\Big )^2 - \sum _{i=1}^n x_i \bigg ) \\&= \frac{1}{2} \bigg ( \sum _{i=1}^n x_i^2 + 2 \sum \limits _{{i<j \in [ n ]}} x_i x_j - \sum _{i=1}^n x_i \bigg )\\&= \sum _{i=1}^n \Bigl (\begin{array}{@{}c@{}}x_i\\ 2\end{array}\Bigr ) + \sum _{i=1}^n\sum _{j=i+1}^n x_ix_j. \end{aligned}$$

Hence, we can reformulate k as follows:

$$\begin{aligned} k&= \sum _{i=1}^n \Big (\Bigl (\begin{array}{@{}c@{}}t'\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}a'_i\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}b'_i\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}c'_i\\ 2\end{array}\Bigr )\Big ) \nonumber \\&= \sum _{i=1}^n \Big (\Bigl (\begin{array}{@{}c@{}}t\\ 2\end{array}\Bigr ) + \Bigl (\begin{array}{@{}c@{}}A\\ 2\end{array}\Bigr ) + \Bigl (\begin{array}{@{}c@{}}B\\ 2\end{array}\Bigr ) + \Bigl (\begin{array}{@{}c@{}}C\\ 2\end{array}\Bigr ) \nonumber \\&+ AB + BC + AC + t(A + B + C)\nonumber \\&-\Bigl (\begin{array}{@{}c@{}}A\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}a_i\\ 2\end{array}\Bigr ) - A a_i - \Bigl (\begin{array}{@{}c@{}}B\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}b_i\\ 2\end{array}\Bigr ) - B b_i - \Bigl (\begin{array}{@{}c@{}}C\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}c_i\\ 2\end{array}\Bigr ) - C c_i\Big ) \nonumber \\&= \sum _{i=1}^n \Big (\Bigl (\begin{array}{@{}c@{}}t\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}a_i\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}b_i\\ 2\end{array}\Bigr ) - \Bigl (\begin{array}{@{}c@{}}c_i\\ 2\end{array}\Bigr ) + AB + BC + AC\nonumber \\&+ (t-a_i)A + (t-b_i)B + (t-c_i)C\Big ). \end{aligned}$$
(2)

As \(1 \le a_i, b_i, c_i \le n^d\), we have \(\binom{a_i}{2} + \binom{b_i}{2} + \binom{c_i}{2} \le 3n^{2d}\le n^{5d} = AB\). Thus, \(k \ge n (AC+BC)\). For the upper bound, observe that \(t \le 3n^d\). Plugging this into (2), we have

$$\begin{aligned} k&\le \sum _{i=1}^n \Big (\Bigl (\begin{array}{@{}c@{}}3n^d\\ 2\end{array}\Bigr ) + AB + BC + AC + 3n^d(A+B+C)\Big )\\&\le nBC + n\big (9n^{2d} + n^{5d} + n^{9d} + 3n^{3d} + 3n^{4d} + 3n^{8d}\big ). \end{aligned}$$

As the right summand is a polynomial in n with degree \(9d+1\) and coefficients in \({\mathcal {O}}(1)\), it is at most nBC for sufficiently large n. Thus, the upper bound follows. \(\square\)

Lemma 13 implies that we cannot merge two large cliques.

Lemma 14

If \(I'\) is a yes-instance, then no solution merges two large cliques.

Proof

Merging two large cliques adds at least \(C^2 = n^{14d}> 2n^{10d+1} = 2nBC > k\) edges, see Lemma 13. \(\square\)

At the same time, we cannot reach our budget unless we merge every medium-sized clique with a large one.

Lemma 15

If \(I'\) is a yes-instance, then in any solution graph, for every \(i\in [ n ]\), the clique \(b'_i\) is merged with exactly one clique \(c'_{\varphi (i)}\), where \(\varphi (i) \in [ n ]\).

Proof

By Lemma 14, we can merge any small clique and any medium-sized clique with at most one large clique. Note that every medium-sized clique that is merged with a large clique contributes more than BC edge additions to our budget. Assume towards a contradiction that there is one medium-sized clique that is not merged with a large clique. Then, the maximum number of edge additions is achieved by merging the other \(n-1\) medium-sized cliques and all n small cliques with the largest clique, leaving the one remaining medium-sized clique and \(n-1\) large cliques untouched. The number of edges added by these merges is at most

$$\begin{aligned}&(n-1)(B+n^d)(C+n^d) + \Bigl (\begin{array}{@{}c@{}}n-1\\ 2\end{array}\Bigr )(B+n^d)^2\\&\quad + n(n-1)(A+n^d)(B+n^d) \\&\quad + n(A+n^d)(C+n^d)+ \Bigl (\begin{array}{@{}c@{}}n\\ 2\end{array}\Bigr )(A+n^d)^2\\&\quad =~ (n-1)BC + R, \end{aligned}$$

where R is a polynomial in n with degree at most \(9d+1\) (due to the summand \(nAC = n^{9d+1}\)) and coefficients in \({\mathcal {O}}(1)\). Thus, for sufficiently large n, we have \(R < n^{10d} = BC\), and the overall number of added edges is less than nBC, which by Lemma 13 is a contradiction.

\(\square\)

Now we know that a significant part of the budget is spent on merging medium-sized cliques with large cliques. Nevertheless, we cannot meet our budget unless we spend the remaining budget on merging small cliques with a large clique as well.

Lemma 16

If \(I'\) is a yes-instance, then in any solution graph, for every \(i\in [ n ]\), the clique \(a'_i\) is merged with exactly one clique \(c'_{\chi (i)}\), where \(\chi (i) \in [ n ]\).

Proof

By Lemma 14 and Lemma 15, we can merge merge any small clique with at most one medium-sized clique and at most one large clique. Assume towards a contradiction that there is one small clique that is not merged with a large clique. Then, the maximum number of edge additions is achieved by merging \(n-1\) small cliques with all n medium-sized cliques and one large clique, and leaving the remaining small clique and \(n-1\) large cliques untouched. The number of edge additions provided by this is at most

$$\begin{aligned}&\Bigl (\begin{array}{@{}c@{}}n-1\\ 2\end{array}\Bigr )(A+n^d)^2 + n(n-1)(A+n^d)(B+n^d)\\&\quad + (n-1)(A+n^d)(C+n^d)\\&\quad + \Bigl (\begin{array}{@{}c@{}}n\\ 2\end{array}\Bigr )(B+n^d)^2 + n(B+n^d)(C+n^d)\\&\quad ={} nBC + (n-1)AC + R, \end{aligned}$$

where R is a polynomial in n with degree at most \(8d+1\) (due to the summand \(n\cdot C \cdot n^d = n^{8d+1}\)) and coefficients in \({\mathcal {O}}(1)\). Thus, for sufficiently large n, we have \(R < n^{9d} = AC\), and the overall number of added edges is less than \(nBC+nAC\), which by Lemma 13 is a contradiction. \(\square\)

Combining Lemmas 14 to 16, we obtain the following.

Lemma 17

If \(I'\) is a yes-instance, then every solution graph consists of exactly n cliques.

Proof

By Lemma 14, no two large cliques can be merged, that is, the solution graph contains at least n cliques. By Lemmas 15 and 16, every medium-sized clique and every small clique must be merged with exactly one large clique, which implies that the solution graph contains at most n cliques. \(\square\)

With Lemma 17 at hand, we can show that the budget k is exactly met if and only if each resulting clique contains \(t'\) vertices.

Lemma 18

If \(I'\) is a yes-instance, then every clique in a solution graph \(G'\) contains \(t'\) vertices.

Proof

By Lemma 17, \(G'\) consists of n cliques. Let their sizes be \(s_1, s_2, \dots , s_n\). Then their sum is \(\sum _{i=1}^n s_i = nt'\); otherwise the Numerical 3D Matching instance I is a no-instance. Next, note that

$$\begin{aligned} |E(G')| = \sum _{i=1}^n \Bigl (\begin{array}{@{}c@{}}s_i\\ 2\end{array}\Bigr )&= \frac{1}{2}\sum _{i=1}^n s_i^2 - \frac{1}{2}\sum _{i=1}^n s_i = \frac{1}{2}\sum _{i=1}^n s_i^2 - \frac{1}{2} nt'. \end{aligned}$$
(3)

As \(|E(G')| = |E(G)| + k = n\binom{t'}{2} = \frac{1}{2} (n{t'^2} - nt')\), we have \(\sum _{i=1}^n s_i^2 = n{t'}^2\).

By the Cauchy-Schwarz inequality, we have

$$\begin{aligned} n \cdot \sum _{i=1}^n s_i^2&= \bigg (\sum _{i=1}^n 1^2\bigg )\bigg (\sum _{i=1}^n s_i^2\bigg ) \ge \bigg (\sum _{i=1}^n 1 \cdot s_i\bigg )^2 \nonumber \\&= (nt')^2 = n \cdot n{t'}^2, \end{aligned}$$
(4)

that is, we have \(\sum _{i=1}^ns_i^2 \ge n{t'}^2\), and the two sides are equal only if \(s_1 = s_2 = \dots = s_n = t'\). \(\square\)

This allows us to prove the desired property of any solution for \(I'\).

Lemma 19

If \(I'\) is a yes-instance, then every clique in a solution graph \(G'\) consists of a small, a medium-sized, and a large clique.

Proof

By Lemma 18, every clique in a solution graph contains exactly \(t'\) vertices. As \(t' = t + A + B + C = t + n^{2d} + n^{3d} + n^{7d}\) and \(t \le 3n^d\), every clique in the solution graph must consist of a small, a medium-sized, and a large clique; otherwise the clique cannot consist of exactly \(t'\) vertices. \(\square\)

Now, proving the backward direction of our reduction is straightforward.

Lemma 20

Let I is an instance of Numerical 3D Matching and let \(I'\) be the instance of Cluster Transformation by Edge Addition obtained by applying Construction 4 on I. If \(I'\) is a yes-instance, then so is I.

Proof

Let S be a solution for instance \(I'\) and let \(G' :=(V(G), E(G) \cup S)\) be the corresponding solution graph. By Lemma 17, \(G'\) consists of n clusters of size \(s_1, s_2, \dots , s_n\). By Lemma 19, there are \(\alpha , \beta , \gamma :[ n ] \rightarrow [ n ]\) such that, for every \(i \in [ n ]\), we have

$$\begin{aligned}{} & {} s_i = a'_{\alpha (i)} + b'_{\beta (i)} + c'_{\gamma (i)} = a_{\alpha (i)} + b_{\beta (i)}\\{} & {} \quad + c_{\gamma (i)} + A + B + C = t + A + B + C. \end{aligned}$$

Hence, \(\alpha , \beta , \gamma\) is a solution for instance I. \(\square\)

We now have everything at hand to prove Theorem 11.

Proof of Theorem 11

We use Construction 4 to build an instance \(I'\) of Cluster Transformation by Edge Addition from a given instance I of Numerical 3D Matching. Clearly, \(I'\) can be computed in polynomial time. By Lemma 12 and Lemma 20, I is a yes-instance if and only if \(I'\) is a yes-instance. \(\square\)

4 Empirical insights into the price of fairness

We now study our model of modification fairness empirically, the focus being the price of modification fairness: How fair are colorblind solutions, and how much do we have to pay (in solution cost and in computation time) in comparison with colorblind solutions, to obtain a (sufficiently) fair solution? In the spirit of Böcker et al. (2011) who studied classic Cluster Editing, we refrain from using our algorithm proving fixed-parameter tractability (Theorems 9 and 10 are rather classification results) but instead rely on mathematical programming to investigate our model of modification fairness.

Setup. We computed optimal solutions for Modification-Fair Cluster Editing using an integer linear programming (ILP) formulation of our problem fed into the commercial solver Gurobi 8.1.1. The ILP formulation is based on the standard formulation for Cluster Editing (Grötschel and Wakabayashi 1989), wherein one has a binary variable \(x_{uv}\) for every \(\{u,v\} \in \binom{V(G)}{2}\), indicating whether or not the solution graph contains the edge \(\{u,v\}\), and three constraints for every vertex triple, which ensure that the triple does not induce a \(P_3\). The formulation can be easily extended to a formulation for Modification-Fair Cluster Editing by adding a constraint that ensures that the upper bound \(\delta\) on our fairness measure \(\Delta _{\textrm{ed}}\) holds. For every \(\{u,v\} \in \binom{V(G)}{2}\) we set \(\eta _{uv} :=1\) if \(\{u, v\} \in E(G)\) and \(\eta _{uv} :=0\) otherwise, and for every \(v \in V(G) = R \uplus B\), we set \(\gamma _v :=|R|\) if \(v \in R\) and \(\gamma _v :=-|B|\) if \(v \in B\). Our ILP formulation now is as follows.

$$\begin{gathered} {\text{minimize:}}\quad \sum _{{\{ u,v\} \in\binom{V(G)}{2}}} ((1 - \eta _{{uv}} )x_{{uv}} + \eta _{{uv}} (1 - x_{{uv}} )) \hfill \\ {\text{subject to:}} + x_{{uv}} + x_{{vw}} - x_{{uw}} \le 1,\quad \quad \quad \quad \quad \quad \{ u,v,w\} \in \textstyle\binom{V(G)}{3} \hfill \\ \quad \quad \quad \quad \; + x_{{uv}} - x_{{vw}} + x_{{uw}} \le 1,\quad \quad \quad \quad \quad \quad \{ u,v,w\} \in \textstyle\binom{V(G)}{3} \hfill \\ \quad \quad \quad \quad \; - x_{{uv}} + x_{{vw}} + x_{{uw}} \le 1,\quad \quad \quad \quad \quad \quad \{ u,v,w\} \in \textstyle\binom{V(G)}{3} \hfill \\ \quad \quad \quad \quad \; - \delta \le \sum _{{\{ u,v\} \in\binom{V(G)}{2}}} \sum\limits_{{w \in \{ u,v\} }} ( (1 - \eta _{{uv}} )x_{{uv}} + \eta _{{uv}} (1 - x_{{uv}} ))/\gamma _{w} \le \delta . \hfill \\ \end{gathered}$$

In order to make the results within the datasets comparable, we introduce a normalized fairness measure \(\Delta _{\textrm{norm}}(S) :=\Delta _{\textrm{ed}}(S)/(\nicefrac {2|S|}{\min \{|R|, |B|\}})\). Clearly, \(\Delta _{\textrm{norm}}(S) \ge 0\), and by our upper bound on \(\Delta _{\textrm{ed}}\) from Observation 1(iii), we have \(\Delta _{\textrm{norm}}(S) \le 1\), and a solution S with \(\Delta _{\textrm{norm}}(S) = 1\) would be maximally unfair. Analogously, we define \(\delta _{\textrm{norm}}:=\delta /(\nicefrac {2k_{\infty }}{\min \{|R|, |B|\}})\), wherein \(k_{\infty }\) is the minimum size of a colorblind (\(\delta = \infty\)) solution. Hence, if \(\delta _{\textrm{norm}}= 0\), then we enforce our solution to be perfectly fair, whereas, if \(\delta _{\textrm{norm}}= 1\), then our instance is an instance of standard Cluster Editing, see the discussion after Observation 1. In Sect. 4.2 we will set \(\delta\) such that it reflects chosen values of \(\delta _{\textrm{norm}}\).

The experiments were run on machines with an Intel Xeon W-2125 4-core 8-thread CPU clocked at 4.0 GHz and 256GB of RAM, running Ubuntu 18.04. All material to reproduce the results is publicly available.Footnote 3

For each instance, we set a time limit of one hour for the solving time (excluding the build time). Whenever Gurobi could not report an optimal solution within that time, we report on the gap obtained in the given time. Recall that, for a minimization problem (such as ours), the gap is defined as \((z_U-z_L)/z_U\), where \(z_U\) is the smallest (feasible) solution and \(z_L\) is the largest solution lower bound that Gurobi could find within the time limit. Hence, the gap is at least zero and, whenever a feasible solution was found, at most one.

Datasets. We evaluate our model on two datasets. The first is the SNAP Facebook data set (Leskovec and Krevl 2014), which lists for each person (vertex) their gender (color) as well as their friends (edge). As this data was gathered from Facebook before 2012, the data on gender is binary. The dataset contains nine graphs. For each of these graphs and for each \(n \in \{20, 40, 80, 120\}\) and each \(p \in \{0.1, \dots , 0.5\}\), we sampled a subgraph with n vertices, roughly pn of which were colored red. As the graphs in the dataset did not have sufficiently large connected components, the goal was to have roughly equally large components. To this end, among all components but the largest, we chose sufficiently many uniformly at random. Then, from the largest component, we used a random breadth-first based approach to select a connected subgraph, wherein we randomly selected the next vertex with a bias towards red or towards blue vertices so as to ensure that (roughly) pn vertices were colored red. For the graphs with \(n = 20, 40\), half of the graphs have one component, and the average number of components is 1.7 and 2.6, respectively. For the graphs with \(n = 80, 120\), half of the graphs have two components, and the remaining graphs have more components; the average number of components is 3.0 and 3.9, respectively. The graphs with \(n = 120\) had a maximum of 9 components. Note that, while in standard Cluster Editing, each connected component can be solved individually, this is not the case for the modification-fair variant as our fairness measure encompasses all components. We decided not to sample any larger graphs as already our standard solver needed more than half an hour on average to solve standard, colorblind Cluster Editing on the largest graphs (see Table 2). The graphs are grouped into four sets according to n.

The second data set is a product co-review graph based on data from Amazon (Leskovec et al. 2007), which was already used to analyze a different fairness model for Cluster Editing (Ahmadian et al. 2020). Herein, we have a vertex for each product and an edge whenever two products were reviewed by the same person. Each vertex belongs to one of five categories out of which we sampled the products. For each (unordered) pair of product categories, each \(n \in \{40, 80, 120, 160, 200\}\), and each \(p \in \{0.1, \dots , 0.5\}\), we sampled subgraphs with roughly n vertices out of the two categories, roughly pn of which belonged to the one category. The sampling procedure was slightly different than the one used for the Facebook graphs: We also used random walks on the smaller connected components so that the proportion of red vertices could be close to pn. Moreover, we selected the same proportion of vertices from the randomly chosen components. For each \(n \in \{40, 80, 120, 160, 200\}\), more than half of the sampled graphs had one component. The average number of components were 1.5, 2.0, 3.0, 3.9, and 4.0, respectively. The graphs with \(n \in \{160,200\}\) had a maximum of 23 connected components. Again, the choice in vertices is reflected by the time it took to solve standard, colorblind Cluster Editing on the graphs (see Table 2). We group the graphs into five sets according to n.

Table 2 gives an overview over the graphs, as well as the minimum solution sizes \(k_\infty\) of colorblind solutions and the running time \(t_\infty\) needed to compute said colorblind solutions.

Table 2 Mean of the number of vertices (n) and edges (m) as well as minimum, mean, and maximum of the solution size \(k_{\infty }\) and running time \(t_{\infty }\) in seconds required to solve standard, colorblind Cluster Editing on the graphs in our dataset

4.1 How fair is the colorblind variant?

We first evaluate the modification fairness of standard, colorblind Cluster Editing.

Fig. 2
figure 2

How fair is the “non-fair” variant? We compare the normed (\(\Delta _{\textrm{norm}}\)) and average (\(\Delta _{\textrm{avg}}\)) modification fairness of the optimal solution for standard Cluster Editing to the number n of vertices and the ratio p red vertices (color). Facebook instances are displayed as triangles, Amazon instances are displayed as circles. As the Facebook instances admit four distinct values of n, we add a random jiggle to make similar entries more distinguishable, that is, for Facebook instances, we display \(n+r\) for \(r \in [-5,5]\) chosen uniformly at random. The average modification fairness (right) is displayed on a log scale; we add \(10^{-4}\) to each entry to make entries with \(\Delta _{\textrm{avg}}= 0\) visible

Figure 2 shows the number n of vertices and the modification fairness for each of our instances when run with \(\delta _{\textrm{norm}}=1\). Overall, \(\Delta _{\textrm{norm}}\) does not exceed 0.52, with \(\Delta _{\textrm{norm}}< 0.055\) for 50% and \(\Delta _{\textrm{norm}}< 0.11\) for 75% of the instances. For the Amazon graphs, the value is slightly higher with \(\Delta _{\textrm{norm}}< 0.07\) for 50% and \(\Delta _{\textrm{norm}}< 0.15\) for 75% of the instances, whereas for Facebook graphs, \(\Delta _{\textrm{norm}}\) does not exceed 0.31 and is less than 0.04 for 50% and less than 0.07 for 75% of the instances.

In Fig. 2, one may observe that for the Facebook instances with \(n = 120\), \(\Delta _{\textrm{norm}}\) does not exceed 0.13, and for all but one of the Facebook instances with \(n=80\), \(\Delta _{\textrm{norm}}\) is below 0.1. Indeed, the means of \(\Delta _{\textrm{norm}}\) are 0.08, 0.05, 0.03 and 0.03 for n being 20, 40, 80 and 120, respectively, that is, \(\Delta _{\textrm{norm}}\) tends to decrease (that is, fairness increases) with increasing number of vertices for the Facebook instances. The same cannot be observed for Amazon graphs. Here, the mean of \(\Delta _{\textrm{norm}}\) is more evenly spread, being 0.11, 0.10, 0.11, 0.11 and 0.12 for n being in (0, 48], (48, 96], (96, 144], (144, 192] and (192, 240], respectively. The figure also suggests that there are more outliers among the Amazon instances. This is backed by the standard deviation, which is 0.052 for the Facebook instances and 0.104 for the Amazon instances.

In the left plot in Fig. 2, one may see that almost all Amazon instances with \(\Delta _{\textrm{norm}}> 0.3\), especially those with more than 100 vertices, have \(p \ge 0.4\). In the right plot, we evaluate \(\Delta _{\textrm{avg}}(S) :=\Delta _{\textrm{ed}}(S)/(2|S|)\), which norms our fairness measure by the size of the solution and hence measures for each vertex not the number of incident edits but the percentage of how many of the overall edits are incident to it. Note that \(\Delta _{\textrm{avg}}= \Delta _{\textrm{norm}}/ \min \{|R|, |B|\} \approx \Delta _{\textrm{norm}}/ (np)\), as \(p \le 0.5\) and roughly np vertices are red. We cannot derive any correlation between p and \(\Delta _{\textrm{avg}}\). We can, however, observe an exponential decay in \(\Delta _{\textrm{avg}}\) with increasing n. Further, we can observe that the Facebook instances tend to have smaller values of \(\Delta _{\textrm{avg}}\) than Amazon instances with similar numbers of vertices. Indeed, for instances with \(n \le 75\), the mean values of \(\Delta _{\textrm{avg}}\) for Facebook and Amazon instances are 0.0092 and 0.0124. For instances with \(75 < n \le 150\), the mean values are 0.0013 for Facebook and 0.0047 for Amazon. The Amazon instances with \(n > 150\) have a mean value of 0.0031.

For small graphs, the modification fairness is rather low, with \(\Delta _{\text {norm}} \ge 0.1\) for 35% of the graphs in Sets 1 and 2. For larger graphs, however, even without imposing fairness constraints the solution is already very fair, the mean value of \(\Delta _{\text {norm}}\) being 0.05 for graphs in Set 4. Figure 2 further shows that our tested graphs do not allow for a statement whether the initial modification fairness correlates with the ratio between red and blue vertices.

4.2 The price of fairness

We next evaluate the price of fairness, that is, how much the solution size and the running time increase when requiring the solutions to be fair, wherein we set \(\delta _{\textrm{norm}}\) to be \(0, 0.01, 0.02, \dots , 0.05\). As the running time for Set 5 of the Amazon graphs was already very close to our time limit, we evaluate the price of fairness only on Sets 1 to 4 for both Facebook and Amazon graphs.

Table 3 How much extra time do we need to be fair? For each of the four sets of the Amazon and Facebook instances, we show the mean computation times in seconds for computing Modification-Fair Cluster Editing with \(\delta _{\textrm{norm}}\) ranging from 1 (colorblind, standard Cluster Editing) to 0 (perfectly fair). Recall that the time limit was set to 3600 seconds

Table 3 shows that requiring perfect fairness results in prohibitively high running time. Allowing a little bit of slack in the fairness however yields significantly lower increments, if any, in running time: In some cases (such as Sets 3 and 4 of the Amazon graphs), the running time for \(\delta _{\textrm{norm}}= 0.05\) is even lower than the one for the colorblind (\(\delta _{\textrm{norm}}=1\)) instance. We remark that for all instances of Sets 1 and 2 with \(\delta _{\textrm{norm}}> 0\) ran within the time limit. For the instances of Set 3 with \(\delta _{\textrm{norm}}>0\), the ILP gap did not exceed 0.03. The gaps for the instances of Set 4 as well as the instances with \(\delta _{\textrm{norm}}=0\) grew as high as 0.65. Of the 170 Facebook instances with \(\delta _{\textrm{norm}}=0\), the solver was able to compute a feasible solution for all but two instances, and ran within the time limit for \(65\%\) of the instances. For the Amazon instances with \(\delta _{\textrm{norm}}=0\), the solver only computed feasible solutions to 98 of the 178 instances, for 26 of which it was able to run within the time limit. As for the instances of Set 4 with \(\delta _{\textrm{norm}}> 0\), 235 out of 288 Amazon instances and 116 out of 240 Facebook instances were solved within the time limit.

Fig. 3
figure 3

How many extra edits do we need to be fair? Each heat map cell contains the mean percentage by which a minimum solution with fairness of \(\delta _{\textrm{norm}}\) is larger than the colorblind solution for Sets 1–4 of the Amazon (A) and Facebook (F) graphs, see Table 2

Let us next consider the percentage by which the solution size k needs to increase in comparison with the minimum colorblind solution \(k_\infty\). As one can see in Fig. 3, the solution size needs to increase only slightly, often by less than \(10\%\), in order to obtain a solution that is almost fair. Requiring perfect fairness \(\delta _{\textrm{norm}}=0\), however, results in a significantly higher increase in solution size. We can also observe that from Sets 1 to Sets 3, there is a downwards trend in the increase in the solution size, but, for Set 4 instances, the increase in solution size becomes larger again. To find a possible explanation for this phenomenon, we ask the reader to examine Fig. 4, in which we compare the solution size increase with the colorblind solution size and the ILP gap.

Fig. 4
figure 4

We compare for each instance the size of a minimum colorblind solution (x-axis) with the percentage by which the minimum fair solution is larger (y-axis) for the set of Amazon and Facebook graphs. Instances whose percentage was above 100 (roughly \(1.2\%\) of the Amazon and \(2.5\%\) of the Facebook instances) are not displayed. The instances are colored by the ILP gap — note that the coloring follows a logarithmic scale (we added \(10^{-3}\) to each gap so as to color zero gaps as well)

We can see for both the Amazon and the Facebook graphs that the fair solution size k tends to be larger whenever the colorblind solution size \(k_\infty\) is small. Since \(k_\infty\) correlates with the number n of vertices (cf. Table 2), this fits our findings in Fig. 3 for Sets 1 through 3 of both the Amazon and Facebook instances. A likely reason for this is that, with the smaller solution size, a single edge has a higher impact on the modification fairness, i.e., balancing out the modifications requires proportionally more edits. A possible answer to why the solution size increases more in graphs with large colorblind solution lies in the gap: The size of the minimum solution may be smaller than the size of the found (feasible) solution by a fraction of the gap. This is most evident for the Facebook instances. The gap may also be an explanation for the large solution size increase for instances with \(\delta _{\textrm{norm}}=0\) which we observed in Fig. 3: As the computation time for the instances with \(\delta _{\textrm{norm}}=0\) often hit the time limit (cf. Table 3), the gap for these instances may also have been very high in comparison to the gap for the colorblind solution. Finally, the sudden decrease in the solution size increase for the Facebook instances of Set 4 with \(\delta _{\textrm{norm}}=0\) compared to the increase with \(\delta _{\textrm{norm}}=0.01\) is likely due to the fact that for those instances that already were hard to solve with \(\delta _{\textrm{norm}}=0.01\), our solver could not find a feasible solution for \(\delta _{\textrm{norm}}=0\) at all.

Discussion. There are four main takeaways. First, on the chosen datasets, the colorblind, standard Cluster Editing solution seems already rather fair. Second, the price of fairness in terms of extra running time is low as long as one does not ask for perfect fairness. However, asking for perfectly fair solutions may become prohibitively expensive. Third, the price of fairness in terms of solution cost is also low as long as one does not ask for perfect fairness. Fourth, in all of the above, the ratio between blue and red vertices does not matter very much.

While we can safely state these takeaways from the presented experiments, they are only a first step in evaluating the price of modification fairness. We would like to conclude this section with some suggestions for future, extended experiments. First of all, we believe that the experiments are slightly impaired by the fixed time limit. For future experiments it may be sensible to choose the time limit some constant factor higher than the running time needed to solve colorblind Cluster Editing on the respective instance. This would allow for a cleaner analysis of the price of fairness in terms of extra running time. Also the analysis of the price of fairness in terms of solution size would improve, as the increasing gaps would no longer interfere with the analysis. Secondly, it would be interesting to study the price of fairness with \(0< \delta _{\textrm{norm}}< 0.01\) to figure out the point at which the price of fairness “explodes”. Maybe choosing the fairness thresholds from an exponential norm (i.e., \(\delta _{\textrm{norm}}= 10^{-1}, 10^{-2}, 10^{-3}, \dots\)) is also more sensible. More generally, it would be interesting to know which fairness threshold should be considered reasonable, or for which fairness threshold one should aim in practice. These questions come in hand with the more general question of what should be defined as “fair”, which is a general contentious issue in fairness in algorithms Pessach and Shmueli (2023).

5 Conclusion

With our work, we hope to have provided a first step towards process-oriented fairness in graph-based data clustering. Focusing on our newly introduced problem Modification-Fair Cluster Editing, there are many research challenges. For instance, in Theorem 10 we showed that Modification-Fair Cluster Editing is fixed-parameter tractable for the parameter number k of edge modifications. The corresponding exponential factor is \(2^{{\mathcal {O}}(k\log k)}\) — can we improve on this or can we exclude a running time of \(2^{o(k\log k)}\) unless the ETH fails?Footnote 4 Further, is Modification-Fair Cluster Editing parameterized by the number of mono-colored edge modifications \(\mu\) fixed-parameter tractable or \(\mathrm {W[1]}\)-hard?

A canonical way to continue the studies on Modification-Fair Cluster Editing is to consider the case of more than two colors. Indeed, for a constant number of colors, a natural extension of our problem should remain fixed-parameter tractable with respect to the number of edge modifications (cf. Theorem 10): The number of cliques to keep then depends on the number of colors. Further, one could study other definitions of fairness over the modifications.

Speaking more generally, one could also combine our process-oriented fairness with other concepts, i.e., the above-mentioned output-oriented fairness Ahmadi et al. (2020); Ahmadian et al. (2020); Ahmadian and Negahbani (2023); Schwartz and Zats (2022). Finally, the fairness investigations could be extended to generalizations of Cluster Editing such as Hierarchical Tree Clustering (Guo et al. 2010), s -Plex Cluster Editing (Guo et al. 2010) or temporal or dynamic versions of Cluster Editing and related problems, e.g. Cluster Editing in temporal graphs (Chen et al. 2018) or dynamic Cluster Editing (Luo et al. 2021).