插入和搜索时间复杂度AVL树
我知道 AVL 树的搜索和插入时间复杂度应该是 O(logn),但是使用我构建的树,当我用执行 N 个操作所需的时间制作一个图时,它最终会成为一个 N 图。这是我得到的图表,Y 是以秒为单位的时间,X 是操作数(插入和搜索)
这应该发生吗?
I know AVL tree's search and insertion time complexity is supposed to be O(logn), but with the tree I built, when I make a graph with the times it takes to do N operations, it ends up beeing a N graph. This is the graph I get, Y is the time in seconds and X is the number of operations (both insert and search)
Is this supposed to happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有当 n 趋于无穷大时,大 o 表示法才是准确的估计。假设您的 AVL 树实现正确,对此的解释可能是大 o 表示法忽略了常量。
如果操作数量增加,图表可能会开始变平。
Big-o notation is only an accurate estimate if n tends to infinity. Assuming your AVL tree is implemented correctly, the explanation for this could be the constants ignored by the big-o notation.
It's likely that the graph would start to flatten if the number of operations increase.