执行连接在O(n)的时间?

编程入门 行业动态 更新时间:2024-10-24 10:27:00
本文介绍了执行连接在O(n)的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法加入2表中的线性时间?我听说这可以通过另一种数据结构(哈希表)来完成,但我不知道如何可以做到这一点。我总是想知道一个加入将涉及跨产品,因此它是O(n ^ 2)。

is there a way to Join 2 tables in linear time? I heard this can be done by having another data structure (Hashtable), but I'm not sure how this can be done. I was always wondering a Join will involve a cross-product and hence it is O(n^2).

推荐答案

算法:

通过表A哈希循环中的所有项目,将它们添加到加入阵列。 通过表B中循环,检查每一个项目,如果它的哈希表中(查看 - O(1)),如果没有,添加到加入表

Loop through table A. Hash all Items, Add them to the Join array. Loop through table B, check each item if it's in the hash table (Check - O(1)), if not, add to the Join table.

更多推荐

执行连接在O(n)的时间?

本文发布于:2023-11-30 17:17:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650859.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!