Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e0ffd0

Browse files
1 parent67f450f commit1e0ffd0

File tree

7 files changed

+180
-176
lines changed

7 files changed

+180
-176
lines changed

‎1473/feed_json_updated.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎1473/feed_rss_created.xml‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎1473/feed_rss_updated.xml‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎1473/geometry/nearest_points.html‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6725,6 +6725,10 @@
67256725

67266726

67276727

6728+
6729+
6730+
6731+
67286732

67296733

67306734

@@ -6737,7 +6741,7 @@
67376741
<ulclass="metadata page-metadata"data-bi-name="page info"lang="en-us"dir="ltr">
67386742

67396743
Last update:
6740-
<spanclass="git-revision-date-localized-plugin git-revision-date-localized-plugin-date"title="June26, 202519:43:19 UTC">June26, 2025</span>&emsp;
6744+
<spanclass="git-revision-date-localized-plugin git-revision-date-localized-plugin-date"title="June28, 202518:31:49 UTC">June28, 2025</span>&emsp;
67416745

67426746
<!-- Tags -->
67436747

@@ -6874,7 +6878,7 @@ <h2 id="implementation">Implementation<a class="headerlink" href="#implementatio
68746878
</code></pre></div>
68756879
<h2id="linear-time-randomized-algorithms">Linear time randomized algorithms<aclass="headerlink"href="#linear-time-randomized-algorithms"title="Permanent link">&para;</a></h2>
68766880
<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">&para;</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 distancethat 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 hasalarger distancethan the two points in the same square.</p>
68786882
<divstyle="text-align: center;">
68796883
<imgsrc="nearest_points_blocks_example.png"alt="Example of the squares strategy"width="350px">
68806884
</div>
@@ -6888,10 +6892,10 @@ <h4 id="choosing-d">Choosing d<a class="headerlink" href="#choosing-d" title="Pe
68886892
<divclass="arithmatex">$$\frac{\lambda(x) n / 8}{n^2 / 2} = \frac{\lambda(x)/4}{n}$$</div>
68896893
<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>
68906894
<divclass="arithmatex">$$1 - \left(1 - \frac{\lambda(x)/4}{n}\right)^n \ge 1 - e^{-\lambda(x)/4}$$</div>
6891-
<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>
68926896
<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>
68936897
<divclass="arithmatex">$$\Pr(\lambda(d) \ge \lambda(x)) = \Pr(d \ge x) \le e^{-\lambda(x)/4} \implies \Pr(\lambda(d) \ge t) \le e^{-t/4} \implies \mathbb{E}[\lambda(d)] \le \int_{0}^{+\infty} e^{-t/4} \, \mathrm{d}t = 4$$</div>
6894-
<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>
68956899
<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>
68966900
<h4id="implementation-of-the-algorithm">Implementation of the algorithm<aclass="headerlink"href="#implementation-of-the-algorithm"title="Permanent link">&para;</a></h4>
68976901
<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
70007004
<p>While this algorithm may look slow, because of recomputing everything multiple times, we can show the total expected cost is linear.</p>
70017005
<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>
70027006
<p>We can therefore see that the expected cost is
7003-
$$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 $$</p>
7007+
<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>
70047008
<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">&para;</a></h2>
70057009
<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>
70067010
<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>
@@ -7016,7 +7020,7 @@ <h2 id="practice-problems">Practice problems<a class="headerlink" href="#practic
70167020

70177021
<ulclass="metadata page-metadata"data-bi-name="page info"lang="en-us"dir="ltr">
70187022
<spanclass="contributors-text">Contributors:</span>
7019-
<ulclass="contributors"data-bi-name="contributors"><li><ahref="https://github.com/singamandeep"title="singamandeep"data-bi-name="contributorprofile"target="_blank">singamandeep</a> (48.8%)</li><li><ahref="https://github.com/izanbf1803"title="izanbf1803"data-bi-name="contributorprofile"target="_blank">izanbf1803</a> (46.71%)</li><li><ahref="https://github.com/adamant-pwn"title="adamant-pwn"data-bi-name="contributorprofile"target="_blank">adamant-pwn</a> (2.1%)</li><li><ahref="https://github.com/jakobkogler"title="jakobkogler"data-bi-name="contributorprofile"target="_blank">jakobkogler</a> (1.5%)</li><li><ahref="https://github.com/Kostero"title="Kostero"data-bi-name="contributorprofile"target="_blank">Kostero</a> (0.3%)</li><li><ahref="https://github.com/SYury"title="SYury"data-bi-name="contributorprofile"target="_blank">SYury</a> (0.3%)</li><li><ahref="https://github.com/avishekp4"title="avishekp4"data-bi-name="contributorprofile"target="_blank">avishekp4</a> (0.3%)</li></ul>
7023+
<ulclass="contributors"data-bi-name="contributors"><li><ahref="https://github.com/singamandeep"title="singamandeep"data-bi-name="contributorprofile"target="_blank">singamandeep</a> (48.8%)</li><li><ahref="https://github.com/izanbf1803"title="izanbf1803"data-bi-name="contributorprofile"target="_blank">izanbf1803</a> (45.81%)</li><li><ahref="https://github.com/adamant-pwn"title="adamant-pwn"data-bi-name="contributorprofile"target="_blank">adamant-pwn</a> (2.1%)</li><li><ahref="https://github.com/jakobkogler"title="jakobkogler"data-bi-name="contributorprofile"target="_blank">jakobkogler</a> (1.5%)</li><li><ahref="https://github.com/mhayter"title="mhayter"data-bi-name="contributorprofile"target="_blank">mhayter</a> (0.9%)</li><li><ahref="https://github.com/Kostero"title="Kostero"data-bi-name="contributorprofile"target="_blank">Kostero</a> (0.3%)</li><li><ahref="https://github.com/SYury"title="SYury"data-bi-name="contributorprofile"target="_blank">SYury</a> (0.3%)</li><li><ahref="https://github.com/avishekp4"title="avishekp4"data-bi-name="contributorprofile"target="_blank">avishekp4</a> (0.3%)</li></ul>
70207024
</ul>
70217025

70227026
</article>

‎1473/search/search_index.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp