自上而下张开树的 makeEmpty() 的时间复杂度

Time Complexity of the makeEmpty() of the Top-Down splay tree

本文关键字:时间复杂度 makeEmpty 张开树 自上而下      更新时间:2023-10-16

在这个张开树的实现中,列出的makeEmpty()函数(删除所有元素)的时间复杂度为O(n)。它的实现方式如下:

 while( !isEmpty( ) )
 {
     findMax( );        // Splay max item to root
     remove( root->element );
 }

鉴于findMaxremove的时间复杂度可能与树的高度成正比,为什么在最坏的情况下需要O(n)时间?

谢谢!

三个词:顺序访问定理。

http://www.wseas.us/e-library/conferences/cairns2001/papers/632.pdf

因为上面的循环反复删除最大值,所以它有效地按顺序访问所有元素,所以我非常确定顺序访问定理适用。