Insertion and Sorting in a Sequence of Numbers Minimizing the Maximum Sum of a Contiguous Subsequence
Let $A$ be a sequence of $n \geq 0$ real numbers. A subsequence of $A$ is a sequence of contiguous elements of $A$. A \emph{maximum scoring subsequence} of $A$ is a subsequence with largest sum of its elements, which can be found in O(n) time by Kadane’s dynamic programming algorithm. We consider in this paper two problems involving maximal scoring subsequences of a sequence. Both of these problems arise in the context of buffer memory minimization in computer networks. The first one, which is called {\sc Insertion in a Sequence with Scores (ISS)}, consists in inserting a given real number $x$ in $A$ in such a way to minimize the sum of a maximum scoring subsequence of the resulting sequence, which can be easily done in $O(n^2)$ time by successively applying Kadane’s algorithm to compute the maximum scoring subsequence of the resulting sequence corresponding to each possible insertion position for $x$. We show in this paper that the ISS problem can be solved in linear time and space with a more specialized algorithm. The second problem we consider in this paper is the {\sc Sorting a Sequence by Scores (SSS)} one, stated as follows: find a permutation $A’$ of $A$ that minimizes the sum of a maximum scoring subsequence. We show that the SSS problem is strongly NP-Hard and give a 2-approximation algorithm for it.
💡 Research Summary
The paper investigates two optimization problems that arise when trying to minimise the size of a buffer in a computer‑network setting. The underlying object is a sequence A of n real numbers. A contiguous subsequence (or subarray) of A is called a scoring subsequence, and the one with the greatest sum is the maximum‑scoring subsequence. Kadane’s linear‑time dynamic‑programming algorithm can compute this value for any fixed sequence.
The first problem, called Insertion in a Sequence with Scores (ISS), asks where to insert a given real number x into A so that the sum of the maximum‑scoring subsequence of the resulting sequence A′ is as small as possible. A naïve solution tries all n + 1 insertion positions and runs Kadane’s algorithm for each, yielding O(n²) time. The authors present a specialised linear‑time algorithm. Their key observation is that inserting x only affects subarrays that cross the insertion point. By pre‑computing for every index i the maximum suffix sum ending at i (the best subarray that ends at i) and the maximum prefix sum starting at i (the best subarray that begins at i), the new maximum after inserting x at position k can be obtained in constant time as the maximum of three quantities: (i) the original global maximum, (ii) the best suffix sum to the left of k plus x, and (iii) x plus the best prefix sum to the right of k. Scanning the array once forward and once backward builds the two auxiliary arrays in O(n) time and O(n) space; a second linear scan evaluates the three candidates for each possible k and records the position that yields the smallest value. Thus ISS is solved in Θ(n) time and space, a dramatic improvement over the quadratic baseline. The algorithm also allows reconstruction of the new maximum‑scoring subsequence if required.
The second problem, Sorting a Sequence by Scores (SSS), asks for a permutation A′ of the original multiset of numbers that minimises the sum of its maximum‑scoring subsequence. The authors prove that SSS is strongly NP‑hard by a reduction from the classic 3‑Partition problem. They construct an instance where each original integer is represented by a pair of numbers (a positive and a negative) arranged in such a way that any optimal ordering must correspond to a perfect 3‑partition of the original set. Consequently, unless P = NP, no polynomial‑time algorithm can solve SSS exactly, even when the numbers are bounded by a polynomial in n.
Despite the hardness result, the paper supplies a simple 2‑approximation algorithm. The algorithm first separates the positive and negative elements of A, sorts the positives in non‑increasing order and the negatives in non‑decreasing order, and then interleaves them (positive, negative, positive, negative, …). This “alternating‑sorted” ordering limits the growth of any prefix sum because large positives are quickly counterbalanced by large (in absolute value) negatives. The authors prove that the maximum‑scoring subsequence in the alternating order is at most twice the optimum value. The proof hinges on bounding the optimal subsequence’s sum from below by the sum of the largest k positives and from above by the sum of the largest k negatives, and showing that the alternating construction never exceeds the sum of the two bounds combined, which is at most twice the optimum. The algorithm runs in O(n log n) time due to the sorting step and uses O(n) additional space.
The motivation behind both problems is the management of buffer memory in packet‑switched networks. In such systems, the buffer must accommodate a contiguous block of data; minimising the worst‑case contiguous demand directly reduces the required memory capacity. ISS corresponds to deciding the optimal insertion point for a newly arriving packet, while SSS corresponds to reordering a batch of packets before they enter the buffer to achieve the smallest possible peak demand.
In summary, the paper makes three principal contributions: (1) a linear‑time, linear‑space algorithm for the ISS problem that replaces the naïve quadratic approach; (2) a proof that the SSS problem is strongly NP‑hard, establishing its computational intractability; and (3) a deterministic 2‑approximation algorithm for SSS that is easy to implement and provably close to optimal. These results bridge theoretical algorithmic analysis with a concrete networking application, and they open avenues for future work such as tighter approximation ratios, fixed‑parameter algorithms for special cases, or experimental evaluation of the proposed heuristics on real traffic traces.