Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 39s1 days 16 hours 1 minutes 39 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 39s1 days 16 hours 1 minutes 39 seconds.

Sign in to watch this lesson
Advanced - Geometry · 4:24
Manhattan distance |Δx| + |Δy| is a sum of one term per coordinate, and that makes three tricks possible. Writing each absolute value as a max of signs turns the farthest pair into max - min of x + y and of x - y (2^d sign masks in d dimensions); the integer map (x, y) → (x + y, y - x) turns Manhattan distance into Chebyshev distance and diamonds into axis-aligned squares. A Manhattan minimum spanning tree only needs each point's nearest neighbour in each of 8 octants, found by a sweep over x + y with an ordered map in 4 passes, then Kruskal.