自上而下张开树的 makeEmpty() 的时间复杂度
Time Complexity of the makeEmpty() of the Top-Down splay tree
在这个张开树的实现中,列出的makeEmpty()
函数(删除所有元素)的时间复杂度为O(n)。它的实现方式如下:
while( !isEmpty( ) )
{
findMax( ); // Splay max item to root
remove( root->element );
}
鉴于findMax
和remove
的时间复杂度可能与树的高度成正比,为什么在最坏的情况下需要O(n)时间?
谢谢!
三个词:顺序访问定理。
http://www.wseas.us/e-library/conferences/cairns2001/papers/632.pdf
因为上面的循环反复删除最大值,所以它有效地按顺序访问所有元素,所以我非常确定顺序访问定理适用。
相关文章:
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- while循环中while循环的时间复杂度是多少
- 我可以创建一个包含两个变量的 for 循环,但时间复杂度仍然为 O(n) 吗?
- 函数的时间复杂度是多少?
- 如何检查两个 std::向量在小于 O(n) 的时间复杂度内是否相等
- 时间复杂度 当具有复合数据类型(如元组或对)时?
- 如何计算此排序函数的时间复杂度?
- 计算两个代码块的时间复杂度
- C++ 中具有 O(1) 搜索时间复杂度的数据结构
- 具有嵌套 if-else 的循环的时间复杂度
- 将树节点添加到向量向量中的 n 元树遍历的平均和最坏情况时间复杂度是多少?
- 如何计算函数的时间复杂度?
- 求解包含"variables"的 T(n) 时间复杂度
- 查找数字是否为 2 的幂的时间复杂度
- C++ - 最坏情况和平均情况插入时间复杂度在 std::unordered_map <int,int>?
- 为什么一种算法在相同的时间复杂度下比另一种算法更快?
- 关于记忆后这种递归关系的时间复杂度
- 2 个嵌套循环的时间复杂度
- 给定C++代码的时间复杂度是多少?
- 自上而下张开树的 makeEmpty() 的时间复杂度