Splay in Virtual Tree in Data Structure

Data Structure AlgorithmsAnalysis of AlgorithmsAlgorithms

In virtual tree, some edges are treated as solid and some are treated as dashed. Usual splaying is performed only in the solid trees. To splay at a node y in the virtual tree, following method is implemented.

The algorithm looks at the tree three times, once in each pass, and changes it. In first pass, by splaying only in the solidtrees, beginning from the node y, the path from y to the root of the overall tree, becomes dashed. This path is createdsolid by splicing. A final splay at node y will now create y the root of the tree. Less informally, the algorithm is explained as follows

Algorithm for Splay(y)

Pass 1 Walk up the virtual tree, but splaying is performed only within solid sub-tree. At the end of this pass, the path from y to root becomes dashed.

Pass 2 Walk up from node y, splicing at each proper ancestor of y. At the end of this step, the path from y to the root becomes solid. Except that, the node y and all its children in the original tree (the one before pass 1) now become left children.

Pass 3 Walk up from node y to the root, splaying in the normal fashion.

This allows us to utilize prior knowledge to improve our probability estimations. For the given set of leaves. So the goal is to construct a tree with the minimum external path weight.

An example is given below

Letter frequency table

Letterzkmcudle
Frequency272432374242120

Huffman code

LetterFreqCodeBits
e12001
d421013
l421103
u3737 1003
c3211104
m24111115
k71111016
z21111006

The Huffman tree (for above example) is given below

raja
Published on 07-Jan-2020 16:47:26
Advertisements