Lably
Skip to content

Leftist tree

Priority queue implemented with a variant of a binary heap

  • 14 min read
  • 5 chapters

Related on Lably

Through Computer science

The height-biased leftist tree was invented by Clark Allan Crane. The name comes from the fact that the left subtree is usually taller than the right subtree.

A leftist tree is a mergeable heap. When inserting a new node into a tree, a new one-node tree is created and merged into the existing tree. To delete an item, it is replaced by the merge of its left and right sub-trees. Both these operations take O(log n) time. For insertions, this is slower than Fibonacci heaps, which support insertion in O(1) (constant) amortized time, and O(log n) worst-case.

Leftist trees are advantageous because of their ability to merge quickly, compared to binary heaps which take Θ(n). In almost all cases, the merging of skew heaps has better performance. However merging leftist heaps has worst-case O(log n) complexity while merging skew heaps has only amortized O(log n) complexity.

Bias

The usual leftist tree is a height-biased leftist tree. However, other biases can exist, such as in the weight-biased leftist tree.

The exact worst-case complexity of both types of leftist trees is 2 log2 n, counting comparisons. The exact amortized complexity of weight-biased leftist trees is known to match the logφ n (approximately 1.44 log2 n) exact amortized complexity of skew heaps, where φ denotes the golden ratio; similarly, the amortized complexity of height-biased leftist trees is bounded below by logφ n, but whether this is also the upper bound is an open problem.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication