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:

    We have not the motive to prepare ourselves for a “life-work” of teaching, of social work—we know that we would lay it down with hallelujah in the height of our success, to make a home for the right man. And all the time in the background of our consciousness rings the warning that perhaps the right man will never come. A great love is given to very few. Perhaps this make-shift time filler of a job is our life work after all.
    Ruth Benedict (1887–1948)

    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)

    The wind had seized the tree and ha, and ha,
    It held the shivering, the shaken limbs,
    Then bathed its body in the leaping lake.
    Wallace Stevens (1879–1955)