You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2id="linear-time-randomized-algorithms">Linear time randomized algorithms<aclass="headerlink" href="#linear-time-randomized-algorithms" title="Permanent link">¶</a></h2>
6876
6880
<h3id="a-randomized-algorithm-with-linear-expected-time">A randomized algorithm with linear expected time<aclass="headerlink" href="#a-randomized-algorithm-with-linear-expected-time" title="Permanent link">¶</a></h3>
6877
-
<p>An alternative method arises from a very simple idea to heuristically improve the runtime: We can divide the plane into a grid of <spanclass="arithmatex">$d \times d$</span> squares, then it is only required to test distances between same-block or adjacent-block points (unless all squares are disconnected from each other, but we will avoid this by design), since any other pair has larger distance that the two points in the same square.</p>
6881
+
<p>An alternative method arises from a very simple idea to heuristically improve the runtime: We can divide the plane into a grid of <spanclass="arithmatex">$d \times d$</span> squares, then it is only required to test distances between same-block or adjacent-block points (unless all squares are disconnected from each other, but we will avoid this by design), since any other pair has a larger distance than the two points in the same square.</p>
6878
6882
<divstyle="text-align: center;">
6879
6883
<imgsrc="nearest_points_blocks_example.png" alt="Example of the squares strategy" width="350px">
<divclass="arithmatex">$$\frac{\lambda(x) n / 8}{n^2 / 2} = \frac{\lambda(x)/4}{n}$$</div>
6889
6893
<p>so the probability of at least one such pair being chosen during the <spanclass="arithmatex">$n$</span> rounds (and therefore finding a smaller <spanclass="arithmatex">$d$</span>) is </p>
<p>(we have used that <spanclass="arithmatex">$(1 + x)^n \le e^{xn}$</span> for any real number <spanclass="arithmatex">$x$</span>, check <ahref="https://en.wikipedia.org/wiki/Bernoulli%27s_inequality#Related_inequalities">this Wikipedia page</a>). <br> Notice this goes to <spanclass="arithmatex">$1$</span> exponentially as <spanclass="arithmatex">$\lambda(x)$</span> increases. This hints that <spanclass="arithmatex">$\lambda$</span> will be small usually.</p>
6895
+
<p>(we have used that <spanclass="arithmatex">$(1 + x)^n \le e^{xn}$</span> for any real number <spanclass="arithmatex">$x$</span>, check <ahref="https://en.wikipedia.org/wiki/Bernoulli%27s_inequality#Related_inequalities">Bernoulli inequalities</a>). <br> Notice this goes to <spanclass="arithmatex">$1$</span> exponentially as <spanclass="arithmatex">$\lambda(x)$</span> increases. This hints that <spanclass="arithmatex">$\lambda$</span> will be small usually.</p>
6892
6896
<p>We have shown that <spanclass="arithmatex">$\Pr(d \le x) \ge 1 - e^{-\lambda(x)/4}$</span>, or equivalently, <spanclass="arithmatex">$\Pr(d \ge x) \le e^{-\lambda(x)/4}$</span>. We need to know <spanclass="arithmatex">$\Pr(\lambda(d) \ge \text{something})$</span> to be able to estimate its expected value. We notice that <spanclass="arithmatex">$\lambda(d) \ge \lambda(x) \iff d \ge x$</span>. This is because making the squares smaller only reduces the number of points in each square (splits the points into other squares), and this keeps reducing the sum of squares. Therefore,</p>
<p>(we have used that <spanclass="arithmatex">$E[X] = \int_0^{+\infty} \Pr(X \ge x) \, \mathrm{d}x$</span>, check <ahref="https://math.stackexchange.com/a/1690829">the proof</a>).</p>
6898
+
<p>(we have used that <spanclass="arithmatex">$E[X] = \int_0^{+\infty} \Pr(X \ge x) \, \mathrm{d}x$</span>, check <ahref="https://math.stackexchange.com/a/1690829">Stackexchange proof</a>).</p>
6895
6899
<p>Finally, <spanclass="arithmatex">$\mathbb{E}[C(d)] = \mathbb{E}[\lambda(d) \, n] \le 4n$</span>, and the expected running time is <spanclass="arithmatex">$O(n)$</span>, with a reasonable constant factor. <spanclass="arithmatex">$\quad \blacksquare$</span></p>
6896
6900
<h4id="implementation-of-the-algorithm">Implementation of the algorithm<aclass="headerlink" href="#implementation-of-the-algorithm" title="Permanent link">¶</a></h4>
6897
6901
<p>The advantage of this algorithm is that it is straightforward to implement, but still has good performance in practise.</p>
@@ -7000,7 +7004,7 @@ <h3 id="an-alternative-randomized-linear-expected-time-algorithm">An alternative
7000
7004
<p>While this algorithm may look slow, because of recomputing everything multiple times, we can show the total expected cost is linear. </p>
7001
7005
<p><strong>Proof.</strong> Let <spanclass="arithmatex">$X_i$</span> the random variable that is <spanclass="arithmatex">$1$</span> when point <spanclass="arithmatex">$p_i$</span> causes a change of <spanclass="arithmatex">$\delta$</span> and a recomputation of the data structures, and <spanclass="arithmatex">$0$</span> if not. It is easy to show that the cost is <spanclass="arithmatex">$O(n + \sum_{i=1}^{n} i X_i)$</span>, since on the <spanclass="arithmatex">$i$</span>-th step we are considering only the first <spanclass="arithmatex">$i$</span> points. However, turns out that <spanclass="arithmatex">$\Pr(X_i = 1) \le \frac{2}{i}$</span>. This is because on the <spanclass="arithmatex">$i$</span>-th step, <spanclass="arithmatex">$\delta$</span> is the distance of the closest pair in <spanclass="arithmatex">$\{p_1,\dots,p_i\}$</span>, and <spanclass="arithmatex">$\Pr(X_i = 1)$</span> is the probability of <spanclass="arithmatex">$p_i$</span> belonging to the closest pair, which only happens in <spanclass="arithmatex">$2(i-1)$</span> pairs out of the <spanclass="arithmatex">$i(i-1)$</span> possible pairs (assuming all distances are different), so the probability is at most <spanclass="arithmatex">$\frac{2(i-1)}{i(i-1)} = \frac{2}{i}$</span>, since we previously shuffled the points uniformly.</p>
<spanclass="arithmatex">$<spanclass="arithmatex">$O(n + \sum_{i=1}^{n} i \Pr(X_i = 1)) \le O(n + \sum_{i=1}^{n} i \frac{2}{i}) = O(3n) = O(n) \quad \quad \blacksquare$</span>$</span></p>
7004
7008
<h2id="generalization-finding-a-triangle-with-minimal-perimeter">Generalization: finding a triangle with minimal perimeter<aclass="headerlink" href="#generalization-finding-a-triangle-with-minimal-perimeter" title="Permanent link">¶</a></h2>
7005
7009
<p>The algorithm described above is interestingly generalized to this problem: among a given set of points, choose three different points so that the sum of pairwise distances between them is the smallest.</p>
7006
7010
<p>In fact, to solve this problem, the algorithm remains the same: we divide the field into two halves of the vertical line, call the solution recursively on both halves, choose the minimum <spanclass="arithmatex">$minper$</span> from the found perimeters, build a strip with the thickness of <spanclass="arithmatex">$minper / 2$</span>, and iterate through all triangles that can improve the answer. (Note that the triangle with perimeter <spanclass="arithmatex">$\le minper$</span> has the longest side <spanclass="arithmatex">$\le minper / 2$</span>.)</p>
0 commit comments