Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

Huffman Trees in Data Structure (ต้นไม้ฮัฟแมน): นิยามและตัวอย่าง

นิยาม

Huffman Coding ให้ Code กับตัวอักษร โดยความยาว Code ขึ้นกับ Relative Frequency (ความถี่สัมพัทธ์) หรือ Weight ของตัวอักษร Huffman Codes เป็น Variable-length และไม่มี Prefix (ไม่มี Code ใดเป็น Prefix ของอีก Code) Prefix-free Binary Code ใดๆ แสดงเป็น Binary Tree ได้ โดยตัวอักษรที่เข้ารหัสอยู่ที่ Leaf

Huffman Tree (Huffman Coding Tree) คือ Full Binary Tree ที่ Leaf แต่ละใบตรงกับตัวอักษรใน Alphabet ที่กำหนด

Huffman Tree ถือเป็น Binary Tree ที่มี Minimum External Path Weight คือ ผลรวม Weighted Path Lengths น้อยที่สุดสำหรับชุด Leaf ที่กำหนด เป้าหมายคือสร้าง Tree ที่มี External Path Weight น้อยที่สุด

ตารางความถี่ตัวอักษร

Letter z k m c u d l e
Frequency 2 7 24 32 37 42 42 120

Huffman Code

Letter Freq Code Bits
e12001
d421013
l421103
u371003
c3211104
m24111115
k71111016
z21111006

Huffman Tree (สำหรับตัวอย่างข้างต้น):

Huffman Trees in Data Structure (ต้นไม้ฮัฟแมน): นิยามและตัวอย่าง