1.
The worst-case performance of the del function is O()?
put
method. The limiting factor on its performance is the height of the binary tree. Recall from the vocabulary section that the height of a tree is the number of edges between the root and the deepest leaf node. The height is the limiting factor because when we are searching for the appropriate place to insert a node into the tree, we will need to do at most one comparison at each level of the tree.put
is \(O(\log_2{n})\text{,}\) where \(n\) is the number of nodes in the tree. Notice that this is the inverse relationship to the calculation in the previous paragraph. So \(\log_2{n}\) gives us the height of the tree, and represents the maximum number of comparisons that put
will need to do as it searches for the proper place to insert a new node.put
method is \(O(n)\text{.}\)
put
method is limited by the height of the tree, you can probably guess that other methods, get, in,
and del
, are limited as well. Since get
searches the tree to find the key, in the worst case the tree is searched all the way to the bottom and no key is found. At first glance del
might seem more complicated, since it may need to search for the successor before the deletion operation can complete. But remember that the worst-case scenario to find the successor is also just the height of the tree which means that you would simply double the work. Since doubling is a constant factor it does not change worst case