Skip to content

Commit 07522b3

Browse files
1 parent fbd38ce commit 07522b3

9 files changed

+79
-37
lines changed

main/feed_json_updated.json

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

main/feed_rss_created.xml

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

main/feed_rss_updated.xml

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

main/geometry/manhattan-distance.html

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6619,7 +6619,7 @@
66196619
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
66206620

66216621
Last update:
6622-
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="April 15, 2025 02:32:08">April 15, 2025</span>&emsp;
6622+
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="April 22, 2025 02:11:52">April 22, 2025</span>&emsp;
66236623

66246624
<!-- Tags -->
66256625

@@ -6687,27 +6687,31 @@ <h2 id="rotating-the-points-and-chebyshev-distance">Rotating the points and Cheb
66876687
<h2 id="manhattan-minimum-spanning-tree">Manhattan Minimum Spanning Tree<a class="headerlink" href="#manhattan-minimum-spanning-tree" title="Permanent link">&para;</a></h2>
66886688
<p>The Manhattan MST problem consists of, given some points in the plane, find the edges that connect all the points and have a minimum total sum of weights. The weight of an edge that connects two points is their Manhattan distance. For simplicity, we assume that all points have different locations.
66896689
Here we show a way of finding the MST in <span class="arithmatex">$O(n \log{n})$</span> by finding for each point its nearest neighbor in each octant, as represented by the image below. This will give us <span class="arithmatex">$O(n)$</span> candidate edges, which, as we show below, will guarantee that they contain the MST. The final step is then using some standard MST, for example, <a href="https://cp-algorithms.com/graph/mst_kruskal_with_dsu.html">Kruskal algorithm using disjoint set union</a>.</p>
6690-
<center>![8 octants picture](manhattan-mst-octants.png)
6691-
6692-
*The 8 octants relative to a point S*</center>
6690+
<div style="text-align: center;">
6691+
<img src="manhattan-mst-octants.png" alt="8 octants picture">
6692+
*The 8 octants relative to a point S*
6693+
</div>
66936694

66946695
<p>The algorithm shown here was first presented in a paper from <a href="https://ieeexplore.ieee.org/document/913303">H. Zhou, N. Shenoy, and W. Nichollos (2002)</a>. There is also another know algorithm that uses a Divide and conquer approach by <a href="https://www.academia.edu/15667173/On_computing_all_north_east_nearest_neighbors_in_the_L1_metric">J. Stolfi</a>, which is also very interesting and only differ in the way they find the nearest neighbor in each octant. They both have the same complexity, but the one presented here is easier to implement and has a lower constant factor.</p>
66956696
<p>First, let's understand why it is enough to consider only the nearest neighbor in each octant. The idea is to show that for a point <span class="arithmatex">$s$</span> and any two other points <span class="arithmatex">$p$</span> and <span class="arithmatex">$q$</span> in the same octant, <span class="arithmatex">$d(p, q) &lt; \max(d(s, p), d(s, q))$</span>. This is important, because it shows that if there was a MST where <span class="arithmatex">$s$</span> is connected to both <span class="arithmatex">$p$</span> and <span class="arithmatex">$q$</span>, we could erase one of these edges and add the edge <span class="arithmatex">$(p,q)$</span>, which would decrease the total cost. To prove this, we assume without loss of generality that <span class="arithmatex">$p$</span> and <span class="arithmatex">$q$</span> are in the octanct <span class="arithmatex">$R_1$</span>, which is defined by: <span class="arithmatex">$x_s \leq x$</span> and <span class="arithmatex">$x_s - y_s &gt; x - y$</span>, and then do some casework. The image below give some intuition on why this is true.</p>
6696-
<center>![unique nearest neighbor](manhattan-mst-uniqueness.png)
6697-
6698-
*Intuitively, the limitation of the octant makes it impossible that $p$ and $q$ are both closer to $s$ than to each other*</center>
6697+
<div style="text-align: center;">
6698+
<img src="manhattan-mst-uniqueness.png" alt="unique nearest neighbor">
6699+
*Intuitively, the limitation of the octant makes it impossible that $p$ and $q$ are both closer to $s$ than to each other*
6700+
</div>
66996701

67006702
<p>Therefore, the main question is how to find the nearest neighbor in each octant for every single of the <span class="arithmatex">$n$</span> points.</p>
67016703
<h2 id="nearest-neighbor-in-each-octant-in-on-log-n">Nearest Neighbor in each Octant in O(n log n)<a class="headerlink" href="#nearest-neighbor-in-each-octant-in-on-log-n" title="Permanent link">&para;</a></h2>
67026704
<p>For simplicity we focus on the NNE octant (<span class="arithmatex">$R_1$</span> in the image above). All other directions can be found with the same algorithm by rotating the input.</p>
67036705
<p>We will use a sweep-line approach. We process the points from south-west to north-east, that is, by non-decreasing <span class="arithmatex">$x + y$</span>. We also keep a set of points which don't have their nearest neighbor yet, which we call "active set". We add the images below to help visualize the algorithm.</p>
6704-
<center>![manhattan-mst-sweep](manhattan-mst-sweep-line-1.png)
6705-
6706-
*In black with an arrow you can see the direction of the line-sweep. All the points below this lines are in the active set, and the points above are still not processed. In green we see the points which are in the octant of the processed point. In red the points that are not in the searched octant.*</center>
6707-
6708-
<center>![manhattan-mst-sweep](manhattan-mst-sweep-line-2.png)
6706+
<div style="text-align: center;">
6707+
<img src="manhattan-mst-sweep-line-1.png" alt="manhattan-mst-sweep">
6708+
*In black with an arrow you can see the direction of the line-sweep. All the points below this lines are in the active set, and the points above are still not processed. In green we see the points which are in the octant of the processed point. In red the points that are not in the searched octant.*
6709+
</div>
67096710

6710-
*In this image we see the active set after processing the point $p$. Note that the $2$ green points of the previous image had $p$ in its north-north-east octant and are not in the active set anymore, because they already found their nearest neighbor.*</center>
6711+
<div style="text-align: center;">
6712+
<img src="manhattan-mst-sweep-line-2.png" alt="manhattan-mst-sweep">
6713+
*In this image we see the active set after processing the point $p$. Note that the $2$ green points of the previous image had $p$ in its north-north-east octant and are not in the active set anymore, because they already found their nearest neighbor.*
6714+
</div>
67116715

67126716
<p>When we add a new point point <span class="arithmatex">$p$</span>, for every point <span class="arithmatex">$s$</span> that has it in its octant we can safely assign <span class="arithmatex">$p$</span> as the nearest neighbor. This is true because their distance is <span class="arithmatex">$d(p,s) = |x_p - x_s| + |y_p - y_s| = (x_p + y_p) - (x_s + y_s)$</span>, because <span class="arithmatex">$p$</span> is in the north-north-east octant. As all the next points will not have a smaller value of <span class="arithmatex">$x + y$</span> because of the sorting step, <span class="arithmatex">$p$</span> is guaranteed to have the smaller distance. We can then remove all such points from the active set, and finally add <span class="arithmatex">$p$</span> to the active set.</p>
67136717
<p>The next question is how to efficiently find which points <span class="arithmatex">$s$</span> have <span class="arithmatex">$p$</span> in the north-north-east octant. That is, which points <span class="arithmatex">$s$</span> satisfy:</p>
@@ -6773,7 +6777,7 @@ <h2 id="problems">Problems<a class="headerlink" href="#problems" title="Permanen
67736777

67746778
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
67756779
<span class="contributors-text">Contributors:</span>
6776-
<ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/NaimSS" title="NaimSS" data-bi-name="contributorprofile" target="_blank">NaimSS</a> (80.0%)</li><li><a href="https://github.com/gabsrp2002" title="gabsrp2002" data-bi-name="contributorprofile" target="_blank">gabsrp2002</a> (11.89%)</li><li><a href="https://github.com/izanbf1803" title="izanbf1803" data-bi-name="contributorprofile" target="_blank">izanbf1803</a> (3.78%)</li><li><a href="https://github.com/mhayter" title="mhayter" data-bi-name="contributorprofile" target="_blank">mhayter</a> (3.24%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (1.08%)</li></ul>
6780+
<ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/NaimSS" title="NaimSS" data-bi-name="contributorprofile" target="_blank">NaimSS</a> (71.95%)</li><li><a href="https://github.com/mhayter" title="mhayter" data-bi-name="contributorprofile" target="_blank">mhayter</a> (11.64%)</li><li><a href="https://github.com/gabsrp2002" title="gabsrp2002" data-bi-name="contributorprofile" target="_blank">gabsrp2002</a> (11.64%)</li><li><a href="https://github.com/izanbf1803" title="izanbf1803" data-bi-name="contributorprofile" target="_blank">izanbf1803</a> (3.7%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (1.06%)</li></ul>
67776781
</ul>
67786782

67796783
</article>

main/graph/edmonds_karp.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6778,7 +6778,7 @@
67786778
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
67796779

67806780
Last update:
6781-
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="April 15, 2025 02:32:08">April 15, 2025</span>&emsp;
6781+
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="April 22, 2025 02:45:52">April 22, 2025</span>&emsp;
67826782

67836783
<!-- Tags -->
67846784

@@ -6870,14 +6870,23 @@ <h2 id="ford-fulkerson-method">Ford-Fulkerson method<a class="headerlink" href="
68706870
<p>We can find the path <span class="arithmatex">$s - A - B - t$</span> with the residual capacities 7, 5, and 8.
68716871
Their minimum is 5, therefore we can increase the flow along this path by 5.
68726872
This gives a flow of 5 for the network.</p>
6873-
<center>![First path](Flow2.png) ![Network after first path](Flow3.png)</center>
6873+
<div style="text-align: center;">
6874+
<img src="Flow2.png" alt="First path">
6875+
<img src="Flow3.png" alt="Network after first path">
6876+
</div>
68746877

68756878
<p>Again we look for an augmenting path, this time we find <span class="arithmatex">$s - D - A - C - t$</span> with the residual capacities 4, 3, 3, and 5.
68766879
Therefore we can increase the flow by 3 and we get a flow of 8 for the network.</p>
6877-
<center>![Second path](Flow4.png) ![Network after second path](Flow5.png)</center>
6880+
<div style="text-align: center;">
6881+
<img src="Flow4.png" alt="Second path">
6882+
<img src="Flow5.png" alt="Network after second path">
6883+
</div>
68786884

68796885
<p>This time we find the path <span class="arithmatex">$s - D - C - B - t$</span> with the residual capacities 1, 2, 3, and 3, and hence, we increase the flow by 1.</p>
6880-
<center>![Third path](Flow6.png) ![Network after third path](Flow7.png)</center>
6886+
<div style="text-align: center;">
6887+
<img src="Flow6.png" alt="Third path">
6888+
<img src="Flow7.png" alt="Network after third path">
6889+
</div>
68816890

68826891
<p>This time we find the augmenting path <span class="arithmatex">$s - A - D - C - t$</span> with the residual capacities 2, 3, 1, and 2.
68836892
We can increase the flow by 1.
@@ -6887,7 +6896,10 @@ <h2 id="ford-fulkerson-method">Ford-Fulkerson method<a class="headerlink" href="
68876896
But because we already have a flow of 3 from <span class="arithmatex">$D$</span> to <span class="arithmatex">$A$</span>, this is possible.
68886897
The intuition of it is the following:
68896898
Instead of sending a flow of 3 from <span class="arithmatex">$D$</span> to <span class="arithmatex">$A$</span>, we only send 2 and compensate this by sending an additional flow of 1 from <span class="arithmatex">$s$</span> to <span class="arithmatex">$A$</span>, which allows us to send an additional flow of 1 along the path <span class="arithmatex">$D - C - t$</span>.</p>
6890-
<center>![Fourth path](Flow8.png) ![Network after fourth path](Flow9.png)</center>
6899+
<div style="text-align: center;">
6900+
<img src="Flow8.png" alt="Fourth path">
6901+
<img src="Flow9.png" alt="Network after fourth path">
6902+
</div>
68916903

68926904
<p>Now, it is impossible to find an augmenting path between <span class="arithmatex">$s$</span> and <span class="arithmatex">$t$</span>, therefore this flow of <span class="arithmatex">$10$</span> is the maximal possible.
68936905
We have found the maximal flow.</p>
@@ -6990,7 +7002,7 @@ <h2 id="practice-problems">Practice Problems<a class="headerlink" href="#practic
69907002

69917003
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
69927004
<span class="contributors-text">Contributors:</span>
6993-
<ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (70.98%)</li><li><a href="https://github.com/DamianArado" title="DamianArado" data-bi-name="contributorprofile" target="_blank">DamianArado</a> (12.05%)</li><li><a href="https://github.com/mhayter" title="mhayter" data-bi-name="contributorprofile" target="_blank">mhayter</a> (5.36%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (3.1300000000000003%)</li><li><a href="https://github.com/infalmo" title="infalmo" data-bi-name="contributorprofile" target="_blank">infalmo</a> (1.79%)</li><li><a href="https://github.com/LUTLJS" title="LUTLJS" data-bi-name="contributorprofile" target="_blank">LUTLJS</a> (1.34%)</li><li><a href="https://github.com/Aryamn" title="Aryamn" data-bi-name="contributorprofile" target="_blank">Aryamn</a> (1.34%)</li><li><a href="https://github.com/Kakalinn" title="Kakalinn" data-bi-name="contributorprofile" target="_blank">Kakalinn</a> (0.89%)</li><li><a href="https://github.com/kd1729" title="kd1729" data-bi-name="contributorprofile" target="_blank">kd1729</a> (0.45%)</li><li><a href="https://github.com/obiwac" title="obiwac" data-bi-name="contributorprofile" target="_blank">obiwac</a> (0.45%)</li><li><a href="https://github.com/shivensinha4" title="shivensinha4" data-bi-name="contributorprofile" target="_blank">shivensinha4</a> (0.45%)</li><li><a href="https://github.com/lm10-piyush" title="lm10-piyush" data-bi-name="contributorprofile" target="_blank">lm10-piyush</a> (0.45%)</li><li><a href="https://github.com/ShayekhBinIslam" title="ShayekhBinIslam" data-bi-name="contributorprofile" target="_blank">ShayekhBinIslam</a> (0.45%)</li><li><a href="https://github.com/wikku" title="wikku" data-bi-name="contributorprofile" target="_blank">wikku</a> (0.45%)</li><li><a href="https://github.com/roll-no-1" title="roll-no-1" data-bi-name="contributorprofile" target="_blank">roll-no-1</a> (0.45%)</li></ul>
7005+
<ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (65.68%)</li><li><a href="https://github.com/mhayter" title="mhayter" data-bi-name="contributorprofile" target="_blank">mhayter</a> (11.86%)</li><li><a href="https://github.com/DamianArado" title="DamianArado" data-bi-name="contributorprofile" target="_blank">DamianArado</a> (11.44%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (2.96%)</li><li><a href="https://github.com/infalmo" title="infalmo" data-bi-name="contributorprofile" target="_blank">infalmo</a> (1.69%)</li><li><a href="https://github.com/LUTLJS" title="LUTLJS" data-bi-name="contributorprofile" target="_blank">LUTLJS</a> (1.27%)</li><li><a href="https://github.com/Aryamn" title="Aryamn" data-bi-name="contributorprofile" target="_blank">Aryamn</a> (1.27%)</li><li><a href="https://github.com/Kakalinn" title="Kakalinn" data-bi-name="contributorprofile" target="_blank">Kakalinn</a> (0.85%)</li><li><a href="https://github.com/kd1729" title="kd1729" data-bi-name="contributorprofile" target="_blank">kd1729</a> (0.42%)</li><li><a href="https://github.com/obiwac" title="obiwac" data-bi-name="contributorprofile" target="_blank">obiwac</a> (0.42%)</li><li><a href="https://github.com/shivensinha4" title="shivensinha4" data-bi-name="contributorprofile" target="_blank">shivensinha4</a> (0.42%)</li><li><a href="https://github.com/lm10-piyush" title="lm10-piyush" data-bi-name="contributorprofile" target="_blank">lm10-piyush</a> (0.42%)</li><li><a href="https://github.com/ShayekhBinIslam" title="ShayekhBinIslam" data-bi-name="contributorprofile" target="_blank">ShayekhBinIslam</a> (0.42%)</li><li><a href="https://github.com/wikku" title="wikku" data-bi-name="contributorprofile" target="_blank">wikku</a> (0.42%)</li><li><a href="https://github.com/roll-no-1" title="roll-no-1" data-bi-name="contributorprofile" target="_blank">roll-no-1</a> (0.42%)</li></ul>
69947006
</ul>
69957007

69967008
</article>

0 commit comments

Comments
 (0)