7
$\begingroup$

Let $\{a_i\}$ and $\{b_i\}$ be non-decreasing sequences of non-negative integers.

How fast can one find $$c_j=\max_{0 \leq i< j}\{a_i+b_{j-i-1}\}$$ for all $0\leq j\leq n-1$?

Naively, it takes $O(n^2)$ time, but I'm hoping monotonicity can help here.

It's easy to observe $\{c_i\}$ is also non-decreasing. If we consider the matrix $M$ where $M_{i,j} = a_i+b_j$, then it is a matrix sorted in both row and column direction, and we are searching for the maximum element in every diagonal.

However, if it's an arbitrary column wise and row wise sorted matrix, this problem require $\Omega(n^2)$ time.

Proof: Let all the numbers below the main diagonal be $\infty$. The elements in the $k$th diagonal are randomly numbers from $(k,k+1)$. Reading any entry provides no information for any other entry.

Edit: This problem is much harder than I anticipated. We can model this problem as a convolution problem over the semiring $(\min,+)$ (take the dual, search for min instead of max), and it can be solved in $O(\frac{n^2}{\log n})$ time according to a Ryan Williams's answer on mathoverflow. It doesn't use the information that the sequence is non-decreasing though.

$\endgroup$
0

2 Answers 2

5
$\begingroup$

Great question! "Distance Transforms of Sampled Functions", by Felzenszwalb and Huttenlocher shows how to compute this in $O(n \lg n)$ time.

"Necklaces, Convolutions, and X+Y", By Bremner et al. shows a $O\left(\frac{n^2}{\frac{\lg^2 n}{(\lg \lg n)^3}}\right)$ algorithm for this problem on the real RAM and a $O(n \sqrt{n})$ algorithm in the nonuniform linear decision tree model.

$\endgroup$
4
  • 1
    $\begingroup$ I see that my problem is a special minimum convolution problem. However the paper doesn't say much about the general case. It requires one of the function to be convex/concave in order to compute in $O(n \log n)$ time. $\endgroup$
    – Chao Xu
    Commented Nov 22, 2013 at 12:11
  • $\begingroup$ I think the first one is $O(\frac{n^2}{\log n})$, the bound you give is for the $(median,+)$ version. $\endgroup$
    – Chao Xu
    Commented Nov 22, 2013 at 20:32
  • 1
    $\begingroup$ See #3 on page 5. $\endgroup$
    – jbapple
    Commented Nov 22, 2013 at 20:54
  • $\begingroup$ I see! my mistake. $\endgroup$
    – Chao Xu
    Commented Nov 22, 2013 at 20:56
0
$\begingroup$

Naively, it takes $O(𝑛^2)$ time, but I'm hoping monotonicity can help here.

Actually, it does. However, monotonicity alone is not sufficient to get faster algorithms. You also need a bounded-input assumption.

Specifically, you can have an $\tilde O(n^{1.5})$-time algorithm if your entries are bounded by $O(n)$ [1]. This has been recently generealized to $\tilde O(n \sqrt{W})$, where $W$ is the largest value in your arrays [2].

See also this post for a similar question: Subquadratic multiplication of polynomials in the max-plus/tropical semiring.

[1] Chi et al. "Faster min-plus product for monotone instances.", https://dl.acm.org/doi/abs/10.1145/3519935.3520057

[2] Bringmann et al. "Even Faster Knapsack via Rectangular Monotone Min-Plus Convolution and Balancing", https://arxiv.org/abs/2404.05681

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.