| Expected-case Cost | Worst-case Cost | ||
| lookup() | O(n) | O(n) | |
| DictLRS | insert() | O(n) | O(n) |
| remove() | O(n) | O(n) | |
| lookup() | O(log n) | O(n) | |
| DictBT | insert() | O(log n) | O(n) |
| remove() | O(log n) | O(n) | |
| lookup() | O(log n) | O(log n) | |
| DictArray | insert() | O(n) | O(n) |
| remove() | O(n) | O(n) | |
| lookup() | O(1) | O(n) | |
| DictHash | insert() | O(1) | O(n) |
| remove() | O(1) | O(n) |


private RotateLeft() {
}
/**
* Trivial
* @param host satisfies the binary search
tree property.
* @param input == null, not used.
* @return host
*/
public Object emptyCase(BiTree host, Object
input) {
throw new IllegalStateException("Can't
rotate an empty tree.");
}
/**
* @param host satisfies the binary search
tree property.
* @param input == null, not used.
* @return subtree with minimum root.
*/
public Object nonEmptyCase(BiTree host, Object
input) {
BiTree right = host.getRightSubTree();
host.setRightSubTree(right.getLeftSubTree());
right.setLeftSubTree(host);
return right;
}
}
lefttreemax = righttreemin
= dummy;
for (;; root = child)
{
if (key < root.key) {
if ((child = root.getleft()) is empty)
break;
if (key < child.key) {
Rotate right.
root = child;
if ((child = root.getleft()) is empty)
break;
}
/* Link into the new root's right tree. */
righttreemin.setleft(root);
righttreemin = root;
} else if (key > root.key) {
if ((child = root.getright()) is empty)
break;
if (key > child.key) {
Rotate left.
root = child;
if ((child = root.getright()) is empty)
break;
}
/* Link into the new root's left tree. */
lefttreemax.setright(root);
lefttreemax = root;
} else
break;
}
/* Assemble the new
root. */
lefttreemax.setright(root.getleft());
righttreemin.setleft(root.getright());
root.setleft(dummy.getright());
root.setright(dummy.getleft());
return (root);
}