Predict the next merge

Heap order for A:5, B:2, C:1, D:1 uses weight then minimum symbol ID.

After merging C,D, which weight-two node comes first?

1 / 5

Resolve the heap

B:2 precedes CD:2 because 1 < 2.

Merge weights: 2,4,9. Their sum 15 equals weighted code length.

Tree codes: A=1, B=00, C=010, D=011.

2 / 5

Canonicalize, keeping lengths

Lengths [1,2,3,3].

Start 0; increment then shift when length grows:

A=0, B=10, C=110, D=111.

Same cost, different encoded bits.

3 / 5

Validate external lengths

At each depth, slots = 2*slots - count[depth].

For [1,1,2], the available slots become 0 then -1: reject.

For [2,2,2], one depth-two slot remains unused: valid.

4 / 5

Transfer task

Assign lengths [2,0,2,3].

Answer: symbol0=00, symbol2=01, symbol3=100.

An unused symbol emits no bits and consumes no code number. A singleton uses one zero bit in this pack.

5 / 5
←/→ or click edges to navigate · ? help · N notes · F fullscreen