Leftist Tree - Initializing A Height Biased Leftist Tree

Initializing A Height Biased Leftist Tree

Initializing a height biased leftist tree is primarily done in one of two ways. The first is to merge each node one at a time into one HBLT. This process is inefficient and takes O(nlogn) time. The other approach is to use a queue to store each node and resulting tree. The first two items in the queue are removed, merged, and placed back into the queue. This can initialize a HBLT in O(n) time. This approach is detailed in the three diagrams supplied. A min height biased leftist tree is shown.

To initialize a min HBLT, place each element to be added to the tree into a queue. In the example (see Part 1 to the left), the set of numbers are initialized. Each line of the diagram represents another cycle of the algorithm, depicting the contents of the queue. The first five steps are easy to follow. Notice that the freshly created HBLT is added to the end of the queue. In the fifth step, the first occurrence of an s-value greater than 1 occurs. The sixth step shows two trees merged with each other, with predictable results.


In part 2 a slightly more complex merge happens. The tree with the lower value (tree x) has a right child, so merge must be called again on the subtree rooted by tree x's right child and the other tree. After the merge with the subtree, the resulting tree is put back into tree x. The s-value of the right child (s=2) is now greater than the s-value of the left child (s=1), so they must be swapped. The s-value of the root node 4 is also now 2.


Part 3 is the most complex. Here, we recursively call merge twice (each time with the right child 's subtree that is not grayed out). This uses the same process described for part 2.


Read more about this topic:  Leftist Tree

Famous quotes containing the words height, biased and/or tree:

    Tell me of the height of the mountains of the moon, or of the diameter of space, and I may believe you, but of the secret history of the Almighty, and I shall pronounce thee mad.
    Henry David Thoreau (1817–1862)

    Scientists are human—they’re as biased as any other group. But they do have one great advantage in that science is a self-correcting process.
    Cyril Ponnamperuma (b. 1923)

    Arise, my love, my fair one, and come away; for now the winter is past, the rain is over and gone. The flowers appear on the earth; the time of singing has come, and the voice of the turtledove is heard in our land. The fig tree puts forth its figs, and the vines are in blossom; they give forth fragrance. Arise, my love, my fair one, and come away.
    Bible: Hebrew, Song of Solomon 2:10-13.