用 C++ 实现二维 kd 树构造算法
我正在开展一个个人项目,用 C++ 实现二维 kd 树构造算法。
我知道有些库已经做到了这一点,但我想获得 C++ 编程经验
(如果您有个人项目要显示,则有助于恢复)
输入:点数以及点本身(可以从命令行读取输入)
我希望它在 O(n log n) 时间内运行,可以这样做吗,如果是的话,有人可以提供一些伪代码来帮助我开始,提前致谢。
I'm working on a personal project to implement a 2-dimensional kd-tree construction algorithm in C++.
I know there are libraries that already do this, but I want to gain experience in C++ programming
(helps in resume if you have personal projects to show)
Input: number of points, and the points themselves (input can be read in from command line)
I want this to run in O(n log n) time, can this be done, if so can someone provide some pseudo-code to help get me started, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近一直在玩 kd-trees。这是一些未经测试的代码。 kd树的构建分两个阶段完成;遍历点列表,O(n),并沿每个维度排序,O(nlogn)。所以,是的,你可以在 O(nlogn) 时间内构建 kd 树。
不过,在树中搜索(假设您正在寻找最近的邻居)会变得更加棘手。我还没有找到任何易于理解的文档。
I've been playing around with kd-trees recently. Here's some untested code. kd-tree construction in done in 2 stages; traversing the list of points, O(n), and sorting along each dimension, O(nlogn). So, yes, you can construct kd-trees in O(nlogn) time.
Searching through the tree (say you are looking for nearest neighbors), gets trickier though. I haven't found any easy-to-follow documentation for that.