Created
February 12, 2018 19:29
-
-
Save jianminchen/c5a3456e721a38cc453469ec27c5b51f to your computer and use it in GitHub Desktop.
Feb. 12, 2018 -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[1, 2,] [4, 3] [6, 3]] | |
find a point which minimizes the sum of the manhattan distance to each point | |
dist = abs(x1 - x2) + abs(y1 - y2) | |
xs = [1, 4, 6] | |
ys = [2, 3, 3] | |
quickselect | |
medianX 4, medianY 3 | |
O(n) | |
Math.abs(x - x1) | |
(x1 + x2 +.. + xn)/ n -> median - 1, 2, 3, 2 , 1, 2, 3, 4 - 2 + 3/ 2 | |
[4,2,3,1] | |
https://en.wikipedia.org/wiki/Quickselect | |
QuickSelect(xs, 1) // average case: O(n) | |
----------------------------- | |
(X:7) 4, 6, 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment