1
在this implementation of a splay tree中,makeEmpty()
函數(刪除所有元素)的所列時間複雜度爲O(n)。它的實現如下:自上而下的splay樹的makeEmpty()的時間複雜度
while(!isEmpty())
{
findMax(); // Splay max item to root
remove(root->element);
}
鑑於這兩個findMax
和remove
可能的時間與樹的高度複雜性,爲什麼會取這個O(n)的時間在最壞的情況下?
謝謝!