But what is a leftist heap, and how is it different from binary heap?
Recall that binary heap is both complete and balanced. Hence it looks something like this:
1 / \ 2 3 / \ / 5 6 7 Fig 1It's clear that it supports O(log N) operations.
In contrast, this is what leftist heap looks like:
1 / \ 3 2 / / 5 7 / 6 Fig 2It's neither complete nor balanced. Yet, it supports O(log N) operations too!
How does it work?