# Leftist heap - determining time complexity

The time complexity of merge (union) operation is said to be $O(\lg (n_1 + n_2))$, where $n_1$ and $n_2$ are the numbers of elements in the merged heaps, respectively. I do not understand this - the algorithm has to go through all the elements of both rightmost paths of the original heaps - lengths of these paths are bound by $O(\lg n_1)$ and $O(\lg n_2)$. That makes $O(\lg n_1 + \lg n_2)$ in total, which is $O(\lg (n_1 n_2))$. Where am I making a mistake in my assumptions?

Arbitrary delete operation - the complexity should be $O(\lg n)$, where $n$ is the size of the heap. But after the deletion, the algorithm has to go through all the nodes from the parent of the deleted node to the root and correct the Leftist property, and the lenght of this path is bound by $O(n)$. Again, where am I wrong?

-
Really arbitrary delete? I only have seen delete-min, which merges the trees at the two children of the root. – Hendrik Jan Feb 24 '13 at 17:31
Yes, arbitrary. I have seen multiple sources saying that arbitrary delete can be done in O(lg n) time provided you use an additional parent pointer for each node. – kenor Feb 24 '13 at 17:39
$\log(x+y) \le \log(xy) \le \log((x+y)^2) = 2\log(x+y)$ (assuming both $x$ and $y$ are positive) – JeffE Feb 26 '13 at 5:58

For the time complexity of merging, JeffE already pointed out in the comments that $O(\log(n_1n_2)) \in O(\log(n_1+n_2))$.
• Thus, the number of updated nodes is bound by the length of a right flank in a leftist tree, which in turn is bound by $O(\log n)$.