NGHỆ THUẬT
LÀM ĐẸP VÀ SỨC KHỎE
THỦ CÔNG
VĂN HÓA VÀ LỊCH SỬ
GIẢI TRÍ
MÔI TRƯỜNG
THỰC PHẨM VÀ ĐỒ UỐNG
KỸ THUẬT NGƯỢC
KHOA HỌC
THỂ THAO
CÔNG NGHỆ
THIẾT BỊ ĐEO
Huffman Coding
Mark

Tạo bởi

Mark

21. tháng Tám 2026FI
1
0
0
0
0

Huffman Coding

Morse weighted its codes by how often letters appear in English generally. Huffman coding does the same thing but computes the weighting for the exact message in front of you, and it produces the provably shortest possible code of its kind. Count the symbols, repeatedly merge the two rarest into a combined node, and the tree you build assigns short codes to common symbols and long codes to rare ones automatically. No code is a prefix of another, so the output needs no separators at all. David Huffman derived it in 1951 as a graduate student — offered the choice of sitting a final exam or solving an open problem, he took the problem, and found the answer his own professor had failed to find.
Trung cấp
1 hour 30 minutes

Hướng dẫn

1

Count the symbols in one specific message

The code is built for this message, not for the language.

  1. Choose a short phrase and tally each letter, spaces included.
  2. Write each symbol on a small card with its count.
  3. Lay the cards out in a row, lowest count first.
Working with physical cards matters here — the algorithm is a sequence of moves, and doing it by hand makes the structure obvious in a way that reading the rule does not.

Vật liệu cho bước này:

Cardstock Assorted Pack (50 Sheets)Cardstock Assorted Pack (50 Sheets)1 gói
Graphite Pencil SetGraphite Pencil Set1 bộ
2

Merge the two rarest, repeatedly

One move, applied until nothing is left to merge.

  1. Take the two cards with the SMALLEST counts.
  2. Place a new card above them whose count is the sum of the two.
  3. Return that new card to the row and re-sort.
  4. Repeat until a single card remains — that is the root.
Each merge buries the two rarest symbols one level deeper, which is what lengthens their codes. The rarest symbols sink; the common ones stay near the top. Nothing decides the code lengths except this repeated move.
3

Read the codes off the tree

The path from the root to a symbol IS its code.

  1. Label every left branch 0 and every right branch 1.
  2. For each symbol, read the labels from root down to that card.
  3. Write out your code table.
  4. Encode the message and count the total bits.
Check the key property: no code is a prefix of any other, because every symbol sits at a LEAF, never on the path to another symbol. That is why the encoded stream can run together with no separators and still decode unambiguously — walk the tree from the root, and each time you hit a leaf you have a symbol.

Vật liệu cho bước này:

Graph PaperGraph Paper1 pad
4

Compare against Morse and against fixed-length

Three codings of one message, measured.

  1. Count the bits your Huffman code needed.
  2. Encode the same message with a fixed 5-bit code per symbol and count.
  3. Now try a message where every symbol appears equally often.
Huffman wins clearly on lopsided messages and gives NO saving at all when every symbol is equally common — with a flat distribution it reduces to fixed-length. That boundary is the honest limit: the saving comes entirely from imbalance. Note too the cost Morse does not pay — the code table itself must travel with the message, so for very short messages Huffman can come out larger overall.
5

History and context

David A. Huffman published the algorithm in 1952, from work done as a graduate student at MIT in 1951. Robert Fano — who with Claude Shannon had devised an earlier top-down method — offered his class a choice between a final exam and solving the problem of finding the most efficient code. Huffman took the problem, worked at it for months, and was on the point of giving up when the bottom-up merging idea arrived. Fano and Shannon had both attempted it top-down; building the tree from the rarest symbols upward is what makes it optimal.

What optimal means here, precisely: no other code that assigns a whole number of bits to each symbol independently can do better. It is not the shortest possible encoding of the message in general — arithmetic coding beats it by escaping the whole-number-of-bits restriction, and methods that spot repeated PHRASES rather than repeated symbols beat it on text that repeats itself.

Where it is used: as a stage inside JPEG, PNG, MP3 and the DEFLATE algorithm behind ZIP and gzip. Those formats first transform the data so that its symbol distribution becomes lopsided, then let Huffman harvest the imbalance. Deployed at that scale, it is likely among the most-executed algorithms in existence.

Its place in the family: tally marks record every occurrence at equal cost; Morse weights by the language's general statistics; Huffman weights by this message's own statistics and proves it cannot be improved on within its rules. Each buys efficiency by knowing more about the data in advance — the theme running through every coding approach in this catalogue.

Vật liệu

3

Blueprint liên quan

Các blueprint này chia sẻ kiến thức — kỹ thuật, vật liệu hoặc nguyên tắc

CC0 Phạm vi công cộng

Bản thiết kế này được phát hành theo CC0. Bạn tự do sao chép, sửa đổi, phân phối và sử dụng cho bất kỳ mục đích nào mà không cần xin phép.

Hỗ trợ nhà sáng tạo bằng cách mua sản phẩm qua bản thiết kế, nơi họ nhận Hoa hồng nhà sáng tạo do nhà bán hàng đặt, hoặc tạo phiên bản mới và kết nối trong bản thiết kế riêng để chia sẻ doanh thu.

Thảo luận

(0)

Đăng nhập để tham gia thảo luận

Đang tải bình luận...