In this implementation of a splay tree, the listed time complexity of the makeEmpty()
function (which removes all elements) is O(n). It is implemented as follows:
while( !isEmpty( ) )
{
findMax( ); // Splay max item to root
remove( root->element );
}
Given that both findMax
and remove
might have time complexity proportional to the height of the tree, why will this take O(n) time in the worst-case?
Thanks!