A short binary label is useful only if the receiver can determine where it ends. For a stream of robot event categories, assigning a different bit string to each category does not by itself make concatenated messages unambiguous. A prefix tree supplies the boundary rule, while the category frequencies determine whether the resulting variable lengths save payload bits.

The following six-symbol example uses invented event counts. It is an analytical coding exercise, not a measured compression benchmark, a radio protocol, or an implementation of a file format. Each symbol is encoded separately with one fixed codebook known to both ends.

Separate distinct labels from decodable streams

Consider a deliberately inadequate three-symbol assignment A = 0, B = 01, and C = 10. The labels are individually different, but message AC produces 010, as does BA. A receiver looking only at that concatenated bit string cannot recover which message was sent.

A prefix code avoids this problem by making each complete symbol label a leaf of a binary tree. No complete label is the beginning of another. The receiver starts at the root, follows incoming bits to a leaf, outputs its symbol, and returns to the root for the next symbol.

RFC 1951 describes this tree interpretation and decoding rule. MIT's information-theory notes give the Kraft condition, expected-length objective, and Huffman construction. The numerical distribution, codebook, payload totals, and distribution-change tests below are original. They are not a reproduction of either reference's example.

Build a code from six original counts

Suppose a record contains 100 event symbols: A occurs 40 times, B 20, C 15, D 10, E 8, and F 7. A fixed-width code needs three bits per symbol to accommodate six labels, so its symbol payload is 300 bits.

For the variable-length construction, repeatedly combine the two smallest remaining weights. First merge F and E, giving 15. The remaining weights are 10, 15, 15, 20, and 40. At the tie, choose C's weight of 15 to merge with D's 10, giving 25. Next merge the other 15 with B's 20, giving 35. Merge 25 and 35 to obtain 60, then merge 60 with A's 40 to reach 100.

That declared tie choice makes this particular tree reproducible. Swapping left and right branches changes bit labels without changing the depths or payload total. Ties can also permit other trees with the same optimal expected length; a claim of one uniquely determined bit string would need an additional convention.

One valid assignment is A = 0, C = 100, D = 101, B = 110, E = 1110, and F = 1111. The lengths in alphabet order A through F are [1, 3, 3, 3, 4, 4]. Each symbol sits at a leaf, and no listed label prefixes another.

Calculate the payload two ways

Multiplying counts by lengths gives 40×1 + 20×3 + 15×3 + 10×3 + 8×4 + 7×4 = 235 bits. Dividing by 100 symbols gives a weighted mean of 2.35 bits per symbol. Relative to the 300-bit fixed-width payload, this particular count table saves 65 bits, about 21.67% of the symbol payload.

The same total follows from the merge weights: 15 + 25 + 35 + 60 + 100 = 235. Each merge adds one bit of depth to every leaf below the new parent, so its weight counts exactly the additional symbol-bit contributions. Summing all merge weights counts each leaf once for every edge on its root-to-leaf path.

This second calculation checks the tree's weighted cost without depending on the chosen zero and one labels. It also shows why an unweighted average of the six lengths is the wrong objective for these counts. That average is 3, while the weighted average is 2.35 because the shortest label belongs to the most frequent symbol.

Use the Kraft budget correctly

For binary prefix lengths, sum the quantities 2 raised to minus each length. Here the total is 1/2 + 3/8 + 2/16 = 1. The tree exactly uses the available binary prefix budget. Assigning two one-bit labels plus any additional positive-length label would exceed one and could not form a prefix code.

The length condition establishes whether some prefix code with those lengths exists. It does not verify every arbitrary assignment of bit strings having those lengths. For example, lengths [1, 2, 2] satisfy the condition, but the earlier labels 0, 01, and 10 remain ambiguous. Labels 0, 10, and 11 realize those same lengths correctly.

Huffman construction minimizes the expected length among symbol-by-symbol binary prefix codes for the declared weights, without an added maximum-length restriction. That scope matters. A code using larger symbol blocks, source context, or a different coding method is a different comparison, and a format may impose extra constraints beyond this exercise.

A changed symbol mix changes the result

Keep the codebook unchanged but make the six symbols equally frequent. Its average length becomes (1 + 3 + 3 + 3 + 4 + 4)/6 = 3 bits per symbol, equal to the fixed-width payload rate. The original advantage depended on the original frequency weighting.

For another hypothetical mix, let F occur half the time and each other symbol one-tenth. The average becomes 0.1×1 + 0.1×3 + 0.1×3 + 0.1×3 + 0.1×4 + 0.5×4 = 3.4 bits per symbol. The same prefix code still decodes correctly but now uses more symbol bits than three-bit fixed labels.

Finally, payload bits are not complete packet size. Codebook descriptions, framing, byte padding, and other fields require their own accounting. Packing the original 235 payload bits into whole bytes alone needs 30 bytes with five padding bits, but this calculation supplies no total-format overhead or transmission measurement. A useful robot telemetry record therefore keeps the codebook, counts, boundary rule, and accounting scope together.

Concept illustration: an existing site-library robot-and-laptop scene supplies telemetry-analysis context. It does not display this code tree, a measured traffic distribution, or an executed compressor.

Sources checked October 24, 2026: MIT, Information Theory course notes, https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/5d8f16adc3385c9ff2975b121bd620e4_MIT6_441S16_course_notes.pdf ; RFC Editor, RFC 1951 section 3.2.1, https://www.rfc-editor.org/rfc/rfc1951 .