如何找到二维数组所有列的最佳匹配?
假设我有一个如下所示的二维数组:
________________
|10|15|14|20|30|
|14|10|73|71|55|
|73|30|42|84|74|
|14|74|XX|15|10|
----------------
正如我所示,列的大小不需要相同。
现在我需要找到每一列的最佳匹配(具有最完全相同的项目和最低的差异的那一列)。当然,我可以在 n^2 中做到这一点,但这对我来说太慢了。我该怎么做呢?
我考虑过一棵 k 维树并为每个树找到最近的邻居,但我不知道它是否好并且它会按我想要的方式工作(可能不会)。
结果例如:
- 第一列很可能是第三列(只有三个不同 - 10、14、42)
- 第二列 ->第五个(只有两个不同 - 15 和 55)
等等等等...:)
Let's say that I have a 2D array that looks like:
________________
|10|15|14|20|30|
|14|10|73|71|55|
|73|30|42|84|74|
|14|74|XX|15|10|
----------------
As I showed, the columns don't need to be same size.
Now I need to find the best matching for each column (the one that has most exactly the same items and lowest different). Of course, I could do that in n^2 but it's too slow for me. How can I do it?
I thought about a k-dimension tree and finding the closest neighbor for every one, but I don't know if it's good and it will work as I want (probably not).
Result for example:
- First column is most likely third (only three different - 10, 14, 42)
- Second column -> fifth (only two different - 15 and 55)
and so on and so on... :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道表中的所有数字都是 2 位数字(即 10 =< x <100),则为每一列创建一个布尔数组,您将在其中标记现有数字:
从那里应该很容易。
If you know that all the numbers in the table are 2-digit numbers (i.e. 10 =< x <100), for each column create an array of booleans where you will mark the existing numbers:
Should be easy from there.