Abstract 1 Introduction 2 Preliminaries 3 Exact Algorithms for Diameter Maximization 4 Maximizing the Sum Dispersion 5 Maximizing the Minimum Dispersion 6 Discussion and Future Work References

Maximizing Diversity in (Near-)Median String Selection

Diptarka Chakraborty ORCID National University of Singapore, Singapore    Rudrayan Kundu111A part of the work was done when the author was doing an internship at the National University of Singapore. Indian Statistical Institute Kolkata, India    Nidhi Purohit222A major part of the work was done when the author was a research fellow at the National University of Singapore. Institute of Mathematical Sciences, Chennai, India    Aravinda Kanchana Ruwanpathirana333The work was done when the author was a research fellow at the National University of Singapore. ORCID Nanyang Technological University, Singapore
Abstract

Given a set of strings over a specified alphabet, identifying a median or consensus string that minimizes the total distance to all input strings is a fundamental data aggregation problem. When the Hamming distance is considered as the underlying metric, this problem has extensive applications, ranging from bioinformatics to pattern recognition. However, modern applications often require the generation of multiple (near-)optimal yet diverse median strings to enhance flexibility and robustness in decision-making.

In this study, we address this need by focusing on two prominent diversity measures: sum dispersion and min dispersion. We first introduce an exact algorithm for the diameter variant of the problem, which identifies pairs of near-optimal medians that are maximally diverse. Subsequently, we propose a (1ε)-approximation algorithm (for any ε>0) for sum dispersion, as well as a bi-criteria approximation algorithm for the more challenging min dispersion case, allowing the generation of multiple (more than two) diverse near-optimal Hamming medians. Our approach primarily leverages structural insights into the Hamming median space and also draws on techniques from error-correcting code construction to establish these results.

Keywords and phrases:
Diversity maximization, Hamming median, diameter, dispersion, approximation algorithms
Copyright and License:
[Uncaptioned image] © Diptarka Chakraborty, Rudrayan Kundu, Nidhi Purohit, and Aravinda Kanchana Ruwanpathirana; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Approximation algorithms analysis
Related Version:
Full Version: https://arxiv.org/abs/2602.10050
Funding:
This work was supported by an MoE AcRF Tier 1 grant (T1 251RES2303).
Editors:
Philip Bille and Nicola Prezza

1 Introduction

In classical optimization problems, the goal is to find an optimal or nearly optimal solution for a given input instance. However, these solutions may not align with the preferences of certain users due to subjective factors like economic considerations, political views, environmental concerns, aesthetics, and more, which the algorithm might not account for. For some users, their personal preferences may outweigh the importance of achieving the optimal solution, making certain approximate solutions more desirable. For instance, a user might favor a cost-effective near-optimal solution over an expensive optimal one due to financial limitations, or an energy-efficient near-optimal solution over an optimal option because of environmental concerns. To address this, it is beneficial to offer users a range of optimal or near-optimal solutions, allowing them to select based on their specific requirements, which the algorithm may not initially know. However, if the solutions provided are too similar, they fail to offer genuine alternatives, undermining the purpose of presenting multiple options. This necessitates the study of returning diverse solutions – specifically, multiple solutions that are far or significantly dissimilar with respect to certain measures in the solution space.

In recent years, there has been an increasing interest in exploring various optimization problems through the perspective of generating diverse solutions [29, 34, 30, 23, 4, 13, 18]. Diverse solutions are crucial in scenarios where decision-making flexibility, robustness against uncertainty, and the ability to encompass multiple viewpoints are vital. For instance, in bioinformatics, particularly in areas like gene motif identification, generating diverse solutions allows for the consideration of multiple motifs, thereby facilitating the investigation of several hypotheses. A range of problems have been studied with the aim of producing multiple diverse solutions, including satisfiability [27, 26, 3], constraint programming [20], hitting set [5], longest common susequence [33], matching [10, 11], shortest paths [16], minimum cut [9], feedback vertex set [5], rank aggregation [2], and spanning tree [17].

Computing a representative of a given data set is one of the most fundamental computational data summarization tasks. In a widely recognized variant of this problem, given a set S of data points coming from an underlying metric space 𝒳, the objective is to find a point (not necessarily from S) that minimizes the sum of distances to the points in S. The problem is referred to as median (or geometric median) problem. The complexity of the problem varies with the underlying metric space. In this paper, we consider the median problem over the well-known Hamming metric. Hamming distance, which counts the number of coordinatewise dissimilarities between a pair of strings, is perhaps the most primitive distance measure defined over strings. In other words, Hamming distance measures the minimum number of character substitutions required to convert one string into another, which is the same as the 1 distance over binary strings. The problem of computing median string under Hamming finds a wide range of applications, ranging from bioinformatics in applications such as gene motif classification [24, 31], classification tasks in pattern recognition [25], and coding theory [12]. It is folklore to compute the Hamming median exactly in linear time. In many applications of Hamming median, we often need to produce a diverse set of solutions; for instance, in selecting a small and diverse set of prototype strings/vectors, in designing diverse consensus sequences capturing different clades/subtypes (e.g., pathogen panels), in choosing query/test inputs that are both representative and diverse across binary feature regions, etc. Despite being a fundamental problem of significant importance, the Hamming median problem has not yet been examined with a focus on diversity. In this paper, we initiate the systematic study of generating diverse (approximate) medians.

Among measures used to quantify diversity, two of the most prominent ones are sum-dispersion – the sum of all pairwise distances, and min-dispersion – the minimum pairwise distance, where the notion of distance depends on the underlying metric space. In diversity maximization, the objective is to maximize either the sum or the min dispersion. In the classical dispersion problem, given a set of points in a metric space, the task is to choose a subset of a specific (input-specified) size that maximizes the sum/min dispersion. The problem is already known to be NP-hard for general metric [32, 1]. For the min dispersion under a general metric, 1/2-approximation is known [32, 19], which is also tight. On the other hand, for the sum dispersion, a 1/2-approximation is known for general metric [19, 6], and it is also known to be tight under the Exponential Time Hypothesis [13]. The min dispersion problem remains NP-hard even when the underlying metric space is the Hamming metric [33], which is the space considered in this work.

The problem becomes much more challenging when the candidate points are not explicitly given, as in diversity variants of many optimization problems, and becomes especially difficult when the solution space is exponential. In the Hamming median problem, the solution set is implicit; moreover, while the optimal median may be unique, the set of approximate medians can be exponential in the length of the strings, making the dispersion problem over this search space computationally more difficult. In many practical scenarios, it is sufficient to output a diverse collection of approximate solutions when the optimal solution is unique, or there are only a few distinct optimal solutions, necessitating the study of generating diverse near-optimal solutions.

Our Contribution

In this paper, we initiate the study of finding diverse (approximate) median strings under the Hamming metric. Let Γ be the alphabet set. Given a set of n strings over alphabet Γ, each of length d, the goal is to compute a set of diverse strings – measured with respect to both sum dispersion and minimum dispersion – that are (1+ε)-approximate medians (for ε0) of the input dataset.

Maximizing diameter.

We start by considering the problem of finding just two (approximate) medians that are as diverse as possible. In the literature, the maximum Hamming distance between two candidate solutions is referred to as the diameter. When focusing on exact medians (i.e., where the solutions are required to be exact medians), it is relatively straightforward to optimally solve the diameter variant. Specifically, we can efficiently find two Hamming medians that are maximally diverse (see the full version) – thanks to the special structure of the space of Hamming medians. However, this same structure often leads to the Hamming median being unique, which precludes the possibility of constructing a diverse set of exact Hamming medians, even of size two.

In many practical settings, it is sufficient to work with near-medians (i.e., (1+ε)-approximate medians for some small ε>0). Consequently, when the aim is to generate diverse solutions and diversity is prioritized over optimality of the underlying solutions, a natural question arises: can we find two approximate medians that are as diverse as possible? We answer this question in the affirmative by presenting an efficient algorithm that optimally solves the diameter problem for approximate Hamming medians.

Theorem 1.

Consider an alphabet Γ. There exists an algorithm that, given any XΓd of size n and ε>0, outputs two (1+ε)-approximate Hamming medians of X with maximum diameter, and runs in time O((1+ε)nd+dlogd).

Maximizing sum dispersion.

Next, we turn our attention to the task of finding multiple – potentially more than two – (approximate) medians that maximize specific diversity measures. As mentioned earlier, one widely used diversity measure is the sum dispersion, where the objective is to maximize the sum of pairwise Hamming distances among the selected solutions. When generating multiple Hamming (exact) medians, it is still feasible – though somewhat more intricate than the diameter variant – to achieve the maximum sum dispersion (see Theorem 9).

The challenge increases when the goal is to compute a diverse set of approximate medians. For approximate medians, we provide a PTAS for the sum dispersion objective.

Theorem 2.

Consider an alphabet Γ. There exists a polynomial-time algorithm that, given any XΓd of size n, a non-negative integer k and ε,δ>0, returns a set S of k (1+ε)-approximate Hamming medians, such that their sum dispersion sumDp(S)(1δ)v, where v is the maximum sum dispersion of k many (1+ε)-approximate Hamming medians.

Maximizing min dispersion.

The problem becomes more challenging when it comes to min dispersion. The goal here is to produce k (approximate) Hamming median strings that maximize the minimum pairwise distance. In contrast to diameter and sum dispersion, this task is computationally more challenging even when seeking exact medians.

In this paper, we provide an efficient algorithm to generate k Hamming medians while approximating the maximum min dispersion. First, we note that when k=O(1), the problem can be solved optimally using standard dynamic programming in polynomial time. So from now, we assume k=Ω(1). We show the following result, a formal statement of which appears in Section 5.

Theorem 3 (Informal Statement).

Given a XΓd, a non-negative integer k, and a δ>0,

  • If the optimal diameter of X is DΩ(1δ2logk), a set of k Hamming medians can be generated in polynomial time, which gives a (1δ)-approximation to the maximum min dispersion with high probability;

  • If DO(1δ2logk), a set of k Hamming medians can be generated in polynomial time, which gives a 1/2-approximation to the maximum min dispersion.

Next, we consider the min dispersion problem over approximate medians. In this case, we provide a bi-criteria algorithm. In particular, we present the following result, a formal statement of which appears in Section 5.

Theorem 4 (Informal Statement).

Given a XΓd, a non-negative integer k, and ε,δ>0,

  • If DO(1), a set of k many (1+ε)-approximate Hamming medians can be generated in polynomial time, with min dispersion at least t/2;

  • If DΩ(1δ2logk), a set of k many (1+2ε)-approximate Hamming medians can be generated in polynomial time, with min dispersion at least (1/2δ)t with high probability,

where D denotes the optimal diameter for (1+ε)-approximate Hamming medians of X and t denotes the maximum min dispersion of a set of k many (1+ε)-approximate Hamming medians of X.

Note that only in the second point of the above result, we attain a bi-criteria approximation. We would also like to highlight that if tΩ(1δdlogk), we can even get a better bi-criteria bound; more specifically, we output a set of (1+ε+δ)-approximate medians with (1/2δ)-approximation to the min dispersion objective, for any δ>0.

Related Works

The max-min and max-sum dispersion problems have been studied in the classical setting, where the goal is to select a subset of points from a given finite metric space. For max-min dispersion, constant-factor approximations are known, including a 1/2-approximation [32, 19], which is known to be tight. For max-sum dispersion, known approximation algorithms achieve a 1/2-approximation in general metrics [19, 6], with the ratio improving to 0.634ε in the 2D Euclidean space [32]. Moreover, under the Exponential Time Hypothesis, no polynomial-time algorithm can approximate k-sum dispersion in general metric spaces within a factor better than 1/2 [13]. The problem remains NP-hard in the Hamming metric, the space we consider in this paper. Better approximation results exist in more structured domains, such as a PTAS for negative-type metrics with matroid constraints [8] and for bounded doubling-dimension metrics [7]. In addition, frameworks have been developed to approximate diversity [15] or to simultaneously guarantee approximate optimality and diversity via bi-criteria reductions to certain budget-constrained problems [13].

Recent work has extended dispersion to broader combinatorial structures, including NP-hard problems such as knapsack, vertex cover, and independent set, with provable approximation guarantees while ensuring a high level of diversity under symmetric-difference as the diversity measure [14]. In graphs and matroids, diverse bases, independent sets, and matchings have been studied, yielding NP-hardness results and fixed-parameter tractable algorithms [11]. Dispersion has also been examined for the Longest Common Subsequence problem, allowing polynomial-time exact algorithms when the number of diverse subsequences is bounded and a PTAS for the max-sum variant [33]. In satisfiability and related NP-complete problems, the diverse-k-SAT problem has been studied, yielding improved exponential-time algorithms and randomized approximations for both min-dispersion and sum-dispersion objectives [3].

Pareto Optimality.

When optimization involves multiple criteria, there may not be a single solution that is optimal for all objectives. In this context, Pareto-optimal solutions have been studied: these are solutions where no objective can be improved without worsening another. Research has focused on computing approximate Pareto fronts. In particular, [28] shows that for any multicriteria optimization problem, there exists a polynomial-size set of Pareto-optimal solutions such that each objective is satisfied up to a factor of (1+ε), and this set can be computed in polynomial time provided a gap version of the problem can be solved. Further, [21, 22] show that for a class of problems in which a dual exists for a restricted version of a budget-constrained optimization problem, if the dual can be solved in polynomial time, it is possible to obtain (1+ε)-approximations for all objectives except one, which can be optimized exactly.

Technical Overview

We start by addressing the challenge of identifying a set of diverse Hamming (exact) medians for a given dataset. We first demonstrate that by exploiting the special structure inherent in the space of all Hamming medians, it is possible to efficiently find diverse Hamming medians, either optimally or through approximation. Subsequently, we discuss methods for obtaining a collection of diverse approximate medians.

Warm-up with Exact medians: Maximizing diameter and dispersions.

Suppose we are given a dataset XΓd, and let w be a Hamming median of X. By a simple observation (Lemma 5), for every index i, the character wi at that position in a Hamming median must be one of the most frequent characters at index i in the dataset X. Therefore, if there are two distinct Hamming medians, they can only differ at those positions where multiple characters are tied for the highest frequency. This observation facilitates the construction of the two most diverse Hamming medians: for each such index, select two different most frequent characters and assign them to these positions in each median, thereby creating two distinct medians.

The scenario becomes less straightforward when the goal is to generate k Hamming medians that maximize the sum of all pairwise Hamming distances (i.e., maximize sum dispersion). Still, the problem remains quite manageable. Since the objective is to maximize the sum, we can focus on optimizing it coordinate-wise. As before, the only indices that contribute to the sum dispersion among Hamming medians are those with multiple most frequent characters. More specifically, for any such index i, suppose there are r most frequent characters, say a1,a2,,ar. Then, the sum dispersion at that index is maximized if each character aj appears exactly k/r times among the k median strings (assuming r divides k; otherwise, the frequencies should be distributed as evenly as possible). It is again easy to generate k Hamming medians that respect the above property, leading to a maximum sum dispersion. We refer to the full version for the details.

The problem becomes much more difficult when it comes to maximizing the min dispersion, i.e., we want to generate k Hamming medians that maximize the minimum pairwise Hamming distances. The computational hardness arises from its innate connection with the minimum distance problem, one of the fundamental questions in error-correcting codes. We begin by giving a dynamic programming algorithm to solve the problem exactly when k=O(1). Thus, from now on, we assume that kΩ(1). Next, we consider the following two cases separately: (I) diameter is Ω(logk), and (II) diameter is O(logk).

For Case (I), we achieve a (1δ)-approximation to the min dispersion (note, for brevity, we hide the dependency on 1/δ2 in the above Ω() and O() notation). Recall that Hamming median requires each index to take only one of the most frequent characters at that index in the input set. Thus, we first compute the set of most frequent characters for each index, denoted as Γi for index i (Γi may contain a single element). Next, we construct a set of k Hamming medians as follows: For each index i, we select a character from Γi independently and uniformly at random. We repeat this process to generate k strings. To argue that this yields a (1δ)-approximation to the min dispersion with high probability, we first apply standard concentration bounds to get a lower bound on the min dispersion of the output set. Then we establish a generalized version of the Plotkin bound for codes with potentially different alphabets in each index. Finally, by combining the lower bound on the min dispersion of the output set and the generalized Plotkin bound, we get our desired approximation guarantee. For Case (II), we observe that the set of all candidate Hamming medians is polynomially bounded, and we then apply the classical greedy algorithm for min dispersion from [32], albeit paying a 1/2-approximation to the min dispersion objective. We refer to the full version for the details.

Approximate medians: Maximizing diameter.

Due to its special structure, the Hamming median is often unique for an input set, particularly when there is a unique majority character at each position. This uniqueness limits the possibility of having multiple diverse medians. However, this restriction does not generally apply to approximate medians, even if we consider an approximation factor of (1+ε), for any small ε>0. For instance, consider an input set X containing n binary strings each of length d such that for every index, the most frequent character is 1 and it occurs in n/2+1 strings (i.e., frequency is n/2+1). Here, the Hamming median is unique (the all-one string). However, it is easy to observe that even if we consider the all-zero string (0d), it is still an (1+ε)-approximate median, for ε8/n, and thus the maximum distance between two (1+ε)-approximate medians (referred to as diameter) could be as large as d.

In this paper, we present an exact algorithm for this diameter variant. Specifically, we design an algorithm that constructs two (1+ε)-approximate medians that are maximally distant from each other. Our approach begins with the string formed by taking the most frequent (majority) character at each position (breaking ties arbitrarily). For each coordinate, we then consider the second most frequent character and assign a weight corresponding to the increase in the median objective if it were chosen instead; this weight is the frequency difference between the most and second most frequent characters. Next, we use a greedy strategy to select a maximal subset T of positions so that the sum of these weights does not exceed 2εopt, where opt denotes the minimum Hamming median objective. Next, we partition this set T in a balanced manner – as evenly as possible into two subsets, T1 and T2, so that the difference in their total weights is minimized. We then output two strings: z, which uses the second most frequent characters at indices in T1 and the most frequent elsewhere; and y, which uses the second most frequent characters at indices in T2 and the most frequent elsewhere. Intuitively, both y and z have a median objective cost of at most (1+ε)opt (due to the balanced partitioning), and since T1 and T2 are disjoint, they are maximally apart. To ensure both y and z are (1+ε)-approximate medians and they realize the maximum diameter (not even off by a small factor), we introduce some additional refinements in the above selection process, leading to a more intricate analysis, which is detailed in the full version.

Approximate medians: Maximizing sum dispersion.

Next, we turn our attention to generating k (more than two) (1+ε)-approximate medians with the aim of maximizing the sum dispersion measure, denoted as sumDp. This introduces new challenges, particularly in adapting and extending the previous approach used for the diameter variant in the case of approximate medians and for maximizing sum dispersion with exact medians. In the case of the diameter, since only two strings are produced, it is sufficient to focus on the two most frequent characters at each position. However, for generating k approximate medians, we may need to consider more than two characters for each index – potentially all characters in Γ – each associated with a different weight. Recall that the weight of a character at a particular index corresponds to the increase in the median objective if it is selected over the most frequent character.

Furthermore, it is no longer enough to simply identify a set of index positions where replacing the most frequent symbol with another does not increase the median cost by more than kεopt, and then “distribute equitably” these positions among the k candidate median strings. First, achieving a balanced partition into k groups is hard, especially since k can be arbitrarily large. Second, and perhaps more importantly, even if such a balanced partitioning is efficiently done and we then make changes to the assigned index set for each of the k candidate medians, this does not guarantee maximization of sumDp. For exact medians, we have already observed that maximizing sumDp coordinate-wise requires using as many distinct symbols as possible, distributed as evenly as possible across the candidate median strings. Now, since each symbol at a given position has potentially different weight, we face a trade-off: whether to increase the number of indices where candidates deviate from the most frequent symbol (thus different from the exact median) or to maximize diversity at certain index positions. In essence, the problem now involves meeting k separate “hard” budget constraints (each having a budget of at most εopt), while still striving to maximize the overall sumDp objective.

To address the challenges outlined above, we first present a (14/D)-approximation algorithm, where D represents the optimal diameter for (1+ε)-approximate medians in the given input set. For any δ>0, our algorithm directly yields a (1δ)-approximation whenever D>4/δ. Otherwise, it is not hard to observe that there are only a polynomial number of possible candidates for the (1+ε)-approximate median strings. We argue that the Hamming metric is of “negative-type” and that the constraint of selecting k strings reduces to a matroid constraint. Then, by applying the result from [8] (which essentially involves rounding a quadratic program), we obtain a PTAS. Next, we briefly outline the main ideas behind the (14/D)-approximation algorithm.

We begin with a set S of k identical exact median strings, all equal to w; we call S the set of candidate medians. We then consider a collection of modification operations. Each operation is specified by: an index position i, a character aΓ, an integer r – the target frequency of a at position i, and an integer – the frequency of the character wi at position i among the candidate medians in S. We assign each operation a density, which informally measures the ratio between its increase in the sumDp objective and its increase in the median objective if applied.

Next, we sort all plausible operations in nondecreasing order of density and attempt to apply the longest prefix of this sorted list that yields a feasible solution. A prefix is feasible if the following holds: we initially allocate a budget of εopt to each candidate median in S. Then, for each index i and character a, we perform all the corresponding operations in the chosen prefix, one by one, on candidate medians that still have positive remaining budget. After each operation, we deduct the appropriate amount from the budget of the candidate median to whom it was applied. If every operation in the prefix can be completed without any candidate median exceeding its budget, the prefix is deemed feasible. In the algorithm, we execute the selected operations in a carefully chosen order and select which candidate medians to modify so as to guarantee the desired approximation.

The approximation guarantee proceeds as follows. Let v denote the optimal sumDp achievable by k many (1+ε)-approximate medians. First, we note that vk2D/4. Next, we derive a lower bound on the sumDp value v attained by our algorithm’s output (the final set of candidate medians). Let U be the total remaining budget across all candidate medians in S at the end of the algorithm, and let ρ be the maximum density among the operations that were not performed. The core of the argument is to establish the two statements: Uρk2, and vvUρ. Informally, Uρ upper-bounds the additional sumDp one could gain by executing all leftover operations without violating any budget constraints. The main technical hurdle lies in proving these two bounds. This immediately yields an approximation factor of (14/D). The details appear in the full version.

Approximate medians: Maximizing min dispersion.

For the problem of selecting k approximate Hamming medians while maximizing the min dispersion, just like the case of exact medians, we can get a dynamic programming algorithm in polynomial time for k=O(1). Thus, from now on, we focus on kΩ(1). Then we split into cases depending on the value of the optimal diameter D. When DO(1), the number of candidate Hamming medians is polynomially bounded; in this case, applying the greedy min-dispersion heuristic [32] yields a 1/2-approximation. For DΩ(logk), we first compute two (1+ε)-approximate Hamming medians y,z of distance equal to the diameter (using Theorem 1). Then for each index i, we create an alphabet set Γi={yi,zi}. Next, we generate k candidate approximate median strings via the following randomized procedure: For each index i, we select a character from Γi independently and uniformly at random, and repeat this process to form k strings. We first argue that each resulting string is an (1+2ε)-approximate median. Using concentration bounds, we establish a lower bound on the min dispersion minDp for these strings, and combining this with the fact that the optimal min dispersion can at most be the diameter, we obtain minDpt/2, where t denotes the optimal minDp achievable by a set of k many (1+ε)-approximate medians. This yields a bi-criteria approximation. We can further improve this approximation factor for the “higher regime” of t. We formulate the problem using an integer linear program and consider its LP relaxation. Then, using a dependent rounding framework, we show that we can generate k many (1+ε+δ)-approximate medians (for any δ>0) with minDp(1/2δ)t. We detailed the arguments in the full version.

2 Preliminaries

Notations.

Let Γ denote an alphabet set. For a string sΓd, we use si to refer to the character at the index i of s. Similarly, for any array (or ordered set) W, we use Wi to denote the element at index i. We use 𝟙(.) to indicate an identity function where for a logical predicate t, 𝟙(t)=1 if t is true; and 0 otherwise. For any XΓd and a string sΓd, let fis(X) indicate the number of times the character si appears at the i-th index of strings in X, i.e., fis(X):=|{xX:xi=si}|=xX𝟙(xi=si). For brevity, when clear from the context, we drop X from the above notation and simply use fis.

For any x,yΓd, their Hamming distance is defined as, H(x,y):=i=1d𝟙(xiyi).

Hamming Median.

Given a set XΓd, the Hamming median problem asks to find a string yΓd that minimizes the sum of distance to the strings in X, i.e., y=argminyΓdxXH(x,y). We use opt(X) (or simply opt when X is clear from the context) to denote xXH(x,y). We call a string yΓd an α-approximate median (for any α1) iff xXH(x,y)αopt.

Finding an (exact) median string under the Hamming distance is folklore. Consider the following string: For any XΓd, the most frequent character string, denoted by mfc(X), is a string w where wi is set to be the most frequently (breaking ties arbitrarily) occurred character at the i-th index in the strings in X, i.e., wi=argmaxeΓ|{xX:xi=e}|, and in the rest of the paper we use w to refer to mfc(X).

It is straightforward to see that w=mfc(X) is a median for the set X under the Hamming distance, as stated in the following result.

Lemma 5 (Folklore).

For any XΓd, w=mfc(X) is an optimal median of X, i.e. xXH(x,w)=opt. Furthermore, for any optimal solution w, fiw=fiw, for all i[d].

Next, we show how the cost of any string can be related to the optimal.

Lemma 6.

For any XΓd, let w=mfc(X). Then, for any sΓd, we can express its objective cost using w and opt as, xXH(x,s)=opt+i:siwi(fiwfis).

Dispersion Measures.

Dispersion is the notion of computing k2 diverse solutions to the Hamming median problem. There are multiple ways we could define the dispersion of a set of strings. In this work, we consider two common forms of dispersion, minimum Hamming distance (min dispersion) and sum of pairwise Hamming distances (sum dispersion). We formally define the min dispersion and sum dispersion as follows:

Definition 7 (Min Dispersion).

Given a set of strings S={s1,s2,,sm}, the min dispersion of S is defined as, minDp(S):=minsi,sjSH(si,sj).

Definition 8 (Sum Dispersion).

Given a set of strings S={s1,s2,,sm}, the sum dispersion of S is defined as, sumDp(S):=si,sjS|i<jH(si,sj).

Diverse Hamming (Approximate) Median.

In this paper, we explore three key problems. We first introduce the Diameter-Maximizing-Median problem, where the goal is to find two (approximate) median strings such that the Hamming distance between them is maximized.

Problem 1 (Diameter Maximization (Diameter-Maximizing-Median)).

Given a set of strings XΓd and ε0, the Diameter-Maximizing-Median problem asks to find two (1+ε)-approximate Hamming medians s1,s2Γd of X such that H(s1,s2) is maximized.

Next, the Sum-Dispersion-Approx-Median problem is to find a k set of (1+ε)-approximate Hamming medians that maximize the sum dispersion.

Problem 2 (Sum Dispersion Approximate Medians (Sum-Dispersion-Approx-Median)).

Given a set of strings XΓd, a non-negative integer k, and ε0, the Sum Dispersion Approximate Hamming medians problem asks to find a set of (cardinality k) strings, S={s1,s2,,sk}Γd such that for all i[k], si is a (1+ε)-approximate Hamming median of X, and the sum dispersion sumDp(S) is maximized.

Finally, we explore the Min-Dispersion-Median problem, where the goal is to find k (approximate) Hamming medians that maximize the minimum dispersion.

Problem 3 (Min Dispersion Hamming Medians (Min-Dispersion-Median)).

Given a set of strings XΓd, a non-negative integer k, and ε0, the Min Dispersion Hamming Medians problem asks to find a set of (cardinality k) strings, S={s1,s2,,sk}Γd such that for all i[k], si is a (1+ε)-approximate Hamming median of X, and the min dispersion minDp(S) is maximized.

3 Exact Algorithms for Diameter Maximization

In this section, we develop efficient algorithms for the Diameter-Maximizing-Median problem. We first claim that when ε=0, a straightforward construction yields two exact medians that maximize the diameter. We then extend this result to the case ε>0, demonstrating that there is still an efficient algorithm that produces two (1+ε)-approximate medians achieving maximum diameter.

Theorem 1. [Restated, see original statement.]

Consider an alphabet Γ. There exists an algorithm that, given any XΓd of size n and ε>0, outputs two (1+ε)-approximate Hamming medians of X with maximum diameter, and runs in time O((1+ε)nd+dlogd).

Algorithm Description.

Suppose we are given XΓd as input, and n=|X|. Next, we define an auxiliary string w^ that consists of the second-most frequent character (if it exists) in each position, more specifically: set w^i=argmaxeΓ{wi}|{xX:xi=e}| (breaking ties arbitrarily).

Before proceeding with the detailed description of our algorithm, let us introduce the following problem, an optimal solution of which is pivotal in our algorithm. Let us consider the Min-Diff Partition problem: Given an n-length array M and a set T[n], the goal is to partition T into two (disjoint) sets T1,T2 (where T=T1T2) such that |iT1MiiT2Mi| is minimized. It is not hard to see that this problem can be solved using a dynamic programming algorithm.

Let us now describe our algorithm. Our algorithm first sorts the indices of [d] in the non-decreasing order of the value of fiwfiw^. The algorithm then greedily selects a maximal set S of indices in the sorted order such that iS(fiwfiw^)εopt. Then, it again selects another maximal set R greedily starting from the index |S|+1 of the sorted order, such that iR(fiwfiw^)εopt. We output the strings z,y where the characters of z are the same as w except for the indices in S (where they become the corresponding character in w^) and the characters of y are the same as w except for the indices in R (where they become the corresponding character in w^). We also consider the set T, which consists of the first |S|+|R|+1 sorted indices. If iT(fiwfiw^)2εopt, we find two partitions of T such that the sum difference between the two partitions is minimized. If T1 and T2 are two partitions such that the cost is (1+ε)opt, we use the partition T1,T2. We output the strings z,y where the characters of z are the same as w except for the indices in S (or T1 when there is a valid partition) and the characters of y are the same as w except for the indices in R (or T1 when there is a valid partition).

We provide the pseudocode along with a detailed analysis in the full version.

4 Maximizing the Sum Dispersion

In this section, we present an approximation algorithm for the Sum-Dispersion-Approx- Median problem. We first show that when ε=0, a simple construction yields k exact medians that maximize the sum dispersion.

Theorem 9.

Consider an alphabet Γ. There exists an algorithm that, given any XΓd of size n and a non-negative integer k, returns k Hamming medians maximizing the sum dispersion, in O(ndlog(min{n,|Γ|})+kd) time.

We design the Sum-Dispersion-Exact Algorithm that ends up giving k strings that maximize sum dispersion. The main idea behind the algorithm is first to find the set of majority (most frequent) characters at each index, and then distribute them “evenly” over k candidate medians (see Figure 1). This will ensure that the sum of pairwise distances between them is maximized. We present the algorithm and detailed analysis in the full version.

Refer to caption
Figure 1: Let Γi={a1,,ar} be set of most frequent characters at the index i. Overview of the characters at index i after the modifications by Sum-Dispersion-Exact Algorithm.

We then generalize to the case ε>0, proving that an efficient algorithm can still be obtained to produce k (1+ε)-approximate medians that approximately maximize the sum dispersion. Let us now recall Theorem 2.

Theorem 2. [Restated, see original statement.]

Consider an alphabet Γ. There exists a polynomial-time algorithm that, given any XΓd of size n, a non-negative integer k and ε,δ>0, returns a set S of k (1+ε)-approximate Hamming medians, such that their sum dispersion sumDp(S)(1δ)v, where v is the maximum sum dispersion of k many (1+ε)-approximate Hamming medians.

The proof of the above theorem proceeds as follows. Given XΓd, let v be the maximum possible sum dispersion for any set of k (1+ε)-approximate medians, and D be the diameter for the (1+ε)-approximate medians. We first establish the following result, which is the key contribution towards attaining our approximation result for the sum dispersion. The proof is deferred to the full version.

Theorem 10.

Consider an alphabet Γ. There exists an algorithm that, given any XΓd of size n, a non-negative integer k and ε>0, returns a set S of k (1+ε)-approximate Hamming medians, such that their sum dispersion sumDp(S)(14D)v, where D is the maximum diameter between two (1+ε)-approximate Hamming medians in X and v is the maximum sum dispersion of k (1+ε)-approximate Hamming medians. Moreover, the algorithm runs in time O(nd|Γ|+d2k4|Γ|2).

We then argue that if D is sufficiently large, this already leads to a PTAS. On the other hand, if D is small, a PTAS can be obtained by arguing that the Hamming metric is of “negative-type” and that the constraint of selecting k strings reduces to a matroid constraint, and then using the earlier work of [8]. Together, it completes the proof of Theorem 2. We defer the details to the full version.

5 Maximizing the Minimum Dispersion

In this section, we study the Min-Dispersion-Median problem. We first show that in the special case of exact medians (ε=0), the problem admits a PTAS, at least for a constant-sized alphabet. More specifically, we show the following result.

Theorem 11.

Given a set of strings X, a parameter k, and two parameters δ,η, there exists an algorithm such that:

  1. (I).

    If k1δ, the algorithm outputs k exact medians with min dispersion at least t, in O(ndlogmin(n,|Γ|)+|Γ|1δd12δ2) time, and,

  2. (II).

    If D4δ2(2logk+1) and k>1δ, then with probability at least 1η, the algorithm outputs k exact medians with min dispersion at least (12δ)t, in O(ndlogmin(n,|Γ|)+(kd|Γ|+k2d)log1η) time, and,

  3. (III).

    If D<4δ2(2logk+1) and k>1δ, the algorithm outputs k exact median strings with min dispersion at least 12t, in O(ndlogmin(n,|Γ|)+|Γ|4δ2k2+8δ2log|Γ|) time.

Here D is the optimal diameter between two exact medians in X, and t is the optimal min dispersion of k exact medians in X.

We now provide a high-level proof idea for the above theorem. We first derive a dynamic programming–based algorithm that exactly solves the minimum dispersion problem, and that establishes Item (I). Next, we consider the case where D is large enough, and show that one can obtain a (1δ)-approximation to the minimum dispersion. In this case, we first find the set Γi of all majority (most frequent) characters per index i, and then generate k candidate medians by drawing a character for an index i uniformly at random from that set Γi. A lower bound on the min dispersion achieved by this randomized process follows from a standard concentration inequality. The main crux of the argument lies in establishing a near-tight upper bound on the optimum min dispersion objective, which we derive by proving a generalized Plotkin bound, and that in turn implies Item (II). Finally, we consider the scenario in which D is small, and demonstrate that a solution achieving a 1/2-approximation to the minimum dispersion can be obtained via a greedy algorithm over a polynomial-sized solution (search) space, establishing Item (III). We defer all the details to the full version.

For the more general case where ε>0, meaning the objective is to compute (1+ε)-approximate medians, we present a bi-criteria approximation algorithm.

Theorem 12.

Given a set of strings X, a parameter k, and two parameters δ,η, there exists an algorithm such that:

  1. (I).

    If k1δ, then the algorithm outputs k (1+ε)-approximate medians with min dispersion at least t, in O((1+ε)1δ|Γ|1δn1δd2δ2) time, and,

  2. (II).

    If D4δ2 and k>1δ, then the algorithm outputs k (1+ε)-approximate medians with min dispersion at least 12t, in O(k2|Γ|4δ2d4δ2+nd|Γ|4δ2d4δ2) time.

  3. (III).

    If D4δ2(2logk+1) and k>1δ, then with probability at least 1η, the algorithm outputs k (1+2ε)-approximate medians with min dispersion at least 1δ2t, in O((1+ε)nd+dlogd+k2dlog1η) time.

  4. (IV).

    If t8+4δδd(2logk+2) and k>1δ, then with probability at least 1η, the algorithm outputs k distinct (1+ε+δ)-medians with min dispersion at least 1δ2t, in O(ndlogmin(n,|Γ|)+(nkd+k9d3)log1η) time.

Here D is the optimal diameter between two (1+ε)-approximate medians in X, and t is the optimal min dispersion of k many (1+ε)-approximate medians in X.

The proofs of Item (I) and (II) are similar to the argument used for the corresponding cases in Theorem 11. For Item (III), we start with two (1+ε)-approximate medians realizing the diameter (obtained from Theorem 1), and generate k candidate approximate medians via a randomized process by selecting characters randomly from these two initial approximate medians. We argue that all these candidates are also (1+2ε)-approximate medians. Then, using a standard concentration bound together with the fact that the min dispersion can at most be the diameter, we derive Item (III). We further improve the bi-criteria approximation in Item (IV) for a large regime by using LP relaxation together with the dependent rounding framework. We provide all the details in the full version.

6 Discussion and Future Work

This paper initiates the study of computing a diverse set of medians in the Hamming metric using two classical dispersion objectives: sum dispersion and minimum dispersion. First, we present an exact algorithm for the diameter variant, which outputs two near-medians with maximum diversity. Second, we address the task of producing multiple (near-)medians and give a PTAS for maximizing sum dispersion. Third, we develop a bi-criteria approximation algorithm for maximizing minimum dispersion.

For the minimum-dispersion objective with k approximate medians, there remains a gap in the regime ω(1)DO(logk), where D denotes the optimal diameter. In this range, we do not have a polynomial-time approximation algorithm; our 1/2-approximation runs in quasipolynomial time (more specifically, (d/D)O(logk)poly(ndk) time) instead. Designing a polynomial-time algorithm with a comparable approximation guarantee in this regime is an immediate open problem. Another open direction is to obtain an approximation factor solely on the dispersion objective (instead of bi-criteria trade-offs). Finally, extending diverse median computation to other metric spaces – such as Euclidean, edit, Jaccard, and Kendall–tau – is an interesting avenue for future work.

References

  • [1] Sofiane Abbar, Sihem Amer-Yahia, Piotr Indyk, Sepideh Mahabadi, and Kasturi R Varadarajan. Diverse near neighbor problem. In Proceedings of the twenty-ninth annual symposium on Computational geometry, pages 207–214, 2013. doi:10.1145/2462356.2462401.
  • [2] Emmanuel Arrighi, Henning Fernau, Daniel Lokshtanov, Mateus de Oliveira Oliveira, and Petra Wolf. Diversity in kemeny rank aggregation: A parameterized approach. In Proceedings of the Thirtieth International Joint Conference on Artificial Intelligence, 2021.
  • [3] Per Austrin, Ioana O Bercea, Mayank Goswami, Nutan Limaye, and Adarsh Srinivasan. Algorithms for the diverse-k-sat problem: the geometry of satisfying assignments. In 52nd International Colloquium on Automata, Languages, and Programming (ICALP 2025), pages 14:1–14:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.ICALP.2025.14.
  • [4] Julien Baste, Michael R Fellows, Lars Jaffke, Tomáš Masařík, Mateus de Oliveira Oliveira, Geevarghese Philip, and Frances A Rosamond. Diversity of solutions: An exploration through the lens of fixed-parameter tractability theory. Artificial Intelligence, 303:103644, 2022. doi:10.1016/J.ARTINT.2021.103644.
  • [5] Julien Baste, Lars Jaffke, Tomáš Masařík, Geevarghese Philip, and Günter Rote. Fpt algorithms for diverse collections of hitting sets. Algorithms, 12(12):254, 2019. doi:10.3390/A12120254.
  • [6] Benjamin E. Birnbaum and Kenneth J. Goldman. An improved analysis for a greedy remote-clique algorithm using factor-revealing lps. In Josep Díaz, Klaus Jansen, José D. P. Rolim, and Uri Zwick, editors, Approximation, Randomization, and Combinatorial Optimization. Algorithms and Techniques, pages 49–60, Berlin, Heidelberg, 2006. Springer Berlin Heidelberg. doi:10.1007/11830924_7.
  • [7] Alfonso Cevallos, Friedrich Eisenbrand, and Sarah Morell. Diversity maximization in doubling metrics. In 29th International Symposium on Algorithms and Computation (ISAAC 2018), pages 33:1–33:12. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2018. doi:10.4230/LIPIcs.ISAAC.2018.33.
  • [8] Alfonso Cevallos, Friedrich Eisenbrand, and Rico Zenklusen. Max-sum diversity via convex programming. In 32nd International Symposium on Computational Geometry (SoCG 2016), pages 26:1–26:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPIcs.SoCG.2016.26.
  • [9] Mark de Berg, Andrés López Martínez, and Frits Spieksma. Finding diverse minimum st cuts. In 34th International Symposium on Algorithms and Computation, 2023.
  • [10] Fedor V Fomin, Petr A Golovach, Lars Jaffke, Geevarghese Philip, and Danil Sagunov. Diverse pairs of matchings. Algorithmica, 86(6):2026–2040, 2024. doi:10.1007/S00453-024-01214-7.
  • [11] Fedor V Fomin, Petr A Golovach, Fahad Panolan, Geevarghese Philip, and Saket Saurabh. Diverse collections in matroids and graphs. Mathematical Programming, 204(1):415–447, 2024. doi:10.1007/S10107-023-01959-Z.
  • [12] Moti Frances and Ami Litman. On covering problems of codes. Theory of Computing Systems, 30:113–119, 1997. doi:10.1007/S002240000044.
  • [13] Jie Gao, Mayank Goswami, CS Karthik, Meng-Tsung Tsai, Shih-Yu Tsai, and Hao-Tsung Yang. Obtaining approximately optimal and diverse solutions via dispersion. In Latin American Symposium on Theoretical Informatics, pages 222–239. Springer, 2022.
  • [14] Waldo Gálvez, Mayank Goswami, Arturo Merino, GiBeom Park, Meng-Tsung Tsai, and Victor Verdugo. A framework for the design of efficient diversification algorithms to NP-hard problems, 2025. arXiv:2501.12261.
  • [15] Tesshu Hanaka, Masashi Kiyomi, Yasuaki Kobayashi, Yusuke Kobayashi, Kazuhiro Kurita, and Yota Otachi. A framework to design approximation algorithms for finding diverse solutions in combinatorial problems. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 37, pages 3968–3976, 2023. doi:10.1609/AAAI.V37I4.25511.
  • [16] Tesshu Hanaka, Yasuaki Kobayashi, Kazuhiro Kurita, See Woo Lee, and Yota Otachi. Computing diverse shortest paths efficiently: A theoretical and experimental study. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 36, pages 3758–3766, 2022. doi:10.1609/AAAI.V36I4.20290.
  • [17] Tesshu Hanaka, Yasuaki Kobayashi, Kazuhiro Kurita, and Yota Otachi. Finding diverse trees, paths, and more. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, pages 3778–3786, 2021. doi:10.1609/AAAI.V35I5.16495.
  • [18] Oussama Hanguir, Will Ma, Jiangze Han, and Christopher Thomas Ryan. Optimizing for strategy diversity in the design of video games. Mathematical Programming, 210(1):335–376, 2025. doi:10.1007/S10107-024-02126-8.
  • [19] Refael Hassin, Shlomi Rubinstein, and Arie Tamir. Approximation algorithms for maximum dispersion. Operations Research Letters, 21(3):133–137, 1997. doi:10.1016/S0167-6377(97)00034-5.
  • [20] Emmanuel Hebrard, Brahim Hnich, Barry O’Sullivan, and Toby Walsh. Finding diverse and similar solutions in constraint programming. In AAAI, volume 5, pages 372–377, 2005. URL: http://www.aaai.org/Library/AAAI/2005/aaai05-059.php.
  • [21] Arne Herzel, Cristina Bazgan, Stefan Ruzika, Clemens Thielen, and Daniel Vanderpooten. One-exact approximate pareto sets. Journal of Global Optimization, 80(1):87–115, May 2021. doi:10.1007/s10898-020-00951-7.
  • [22] Arne Herzel, Stefan Ruzika, and Clemens Thielen. Approximation methods for multiobjective optimization problems: A survey. INFORMS J. on Computing, 33(4):1284–1299, October 2021. doi:10.1287/ijoc.2020.1028.
  • [23] Linnea Ingmar, Maria Garcia de la Banda, Peter J Stuckey, and Guido Tack. Modelling diversity of solutions. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 34, pages 1528–1535, 2020. doi:10.1609/AAAI.V34I02.5512.
  • [24] Mohammad Shibli Kaysar and Mohammad Ibrahim Khan. A modified median string algorithm for gene regulatory motif classification. Symmetry, 12(8), 2020. doi:10.3390/sym12081363.
  • [25] C.D. Martinez-Hinarejos, A. Juan, and F. Casacuberta. Use of median string for classification. In Proceedings 15th International Conference on Pattern Recognition. ICPR-2000, volume 2, pages 903–906 vol.2, 2000. doi:10.1109/ICPR.2000.906220.
  • [26] Neeldhara Misra, Harshil Mittal, and Ashutosh Rai. On the parameterized complexity of diverse SAT. In 35th International Symposium on Algorithms and Computation (ISAAC 2024), pages 50:1–50:18. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ISAAC.2024.50.
  • [27] Alexander Nadel. Generating diverse solutions in sat. In International Conference on Theory and Applications of Satisfiability Testing, pages 287–301. Springer, 2011. doi:10.1007/978-3-642-21581-0_23.
  • [28] C.H. Papadimitriou and M. Yannakakis. On the approximability of trade-offs and optimal access of web sources. In Proceedings 41st Annual Symposium on Foundations of Computer Science, pages 86–92, 2000. doi:10.1109/SFCS.2000.892068.
  • [29] Thierry Petit and Andrew C Trapp. Finding diverse solutions of high quality to constraint optimization problems. In IJCAI. International Joint Conference on Artificial Intelligence, 2015.
  • [30] Thierry Petit and Andrew C Trapp. Enriching solutions to combinatorial problems via solution engineering. INFORMS Journal on Computing, 31(3):429–444, 2019. doi:10.1287/IJOC.2018.0855.
  • [31] Pavel Pevzner. Computational molecular biology: an algorithmic approach. MIT press, 2000.
  • [32] D. J. Rosenkrantz S. S. Ravi and G. K. Tayi. Heuristic and special case algorithms for dispersion problems. Oper. Res., 42(2):299–310, April 1994. doi:10.1287/opre.42.2.299.
  • [33] Yuto Shida, Giulia Punzi, Yasuaki Kobayashi, Takeaki Uno, and Hiroki Arimura. Finding diverse strings and longest common subsequences in a graph. In 35th Annual Symposium on Combinatorial Pattern Matching (CPM 2024), pages 27:1–27:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.CPM.2024.27.
  • [34] Satya Gautam Vadlamudi and Subbarao Kambhampati. A combinatorial search perspective on diverse solution generation. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 30, 2016.