huff-op.html
来自「Data Structure Ebook」· HTML 代码 · 共 82 行
HTML
82 行
<HTML><HEAD>
<TITLE>Data Structures and Algorithms: Huffman Encoding</TITLE>
<META name="description" content="Data Structures and Algorithms Course Notes,
PLDS210 University of Western Australia">
<META name="keywords" content="data structures,algorithms,huffman encoding">
</HEAD>
<BODY BGCOLOR="#ffffff">
<TABLE BGCOLOR="#00c0f0" WIDTH="100%" CELLSPACING=0 CELLPADDING=0>
<TR BGCOLOR="#00f0f0"><TD ALIGN=right>
<FONT FACE=helvetica SIZE=+1><I>Data Structures and Algorithms</I></FONT>
</TD></TR>
<TR><TD><FONT FACE=helvetica SIZE=+2><B>Operation of the Huffman algorithm</B></FONT>
</TD></TR>
</TABLE>
<P>
These diagrams show how a Huffman encoding tree is built
using a straight-forward greedy algorithm which combines the
two smallest-weight trees at every step.
<TABLE BORDER=1>
<TR><TD><IMG SRC="huffop1.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop1.gif"></TD>
<TD>Initial data sorted by frequency</TD>
</TR>
<TR><TD><IMG SRC="huffop2.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop2.gif"></TD>
<TD>Combine the two lowest frequencies,<BR>
<B>F</B> and <B>E</B>, to form a sub-tree<BR>
of weight 14.
<P>Move it into its correct place.</TD>
</TR>
<TR><TD><IMG SRC="huffop3.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop3.gif"></TD>
<TD>Again combine the two lowest frequencies,<BR>
<B>C</B> and <B>B</B>, to form a sub-tree<BR>
of weight 25.
<P>Move it into its correct place.</TD>
</TR>
<TR><TD><IMG SRC="huffop4.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop4.gif"></TD>
<TD>Now the sub-tree with weight, 14, and
<B>D</B> are combined to make a tree of
weight, 30.
<P>
Move it to its correct place.</TD>
</TR>
<TR><TD><IMG SRC="huffop5.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop5.gif"></TD>
<TD>Now the two lowest weights are held by the
"25" and "30" sub-trees, so combine them to
make one of weight, 55.
<P>
Move it after the <B>A</B>.</TD>
<TR><TD><IMG SRC="huffop6.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/fig/huffop6.gif"></TD>
<TD>Finally, combine the <B>A</B> and the
"55" sub-tree to produce the final tree.
<P>
The encoding table is:
<PRE>
A 0
C 100
B 101
F 1100
E 1101
D 111
</PRE>
</TD>
</TR>
</TABLE>
<P>
<TABLE CELLPADDING=5 WIDTH="100%" BGCOLOR="#00f0f0" CELLSPACING=4>
<TR><TD WIDTH=50%>
Back to <A HREF="huffman.html" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/huffman.html">Huffman encoding</A></TD>
<TD>Back to the <A HREF="ds_ToC.html" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html">Table of Contents</A>
</TD></TR></TABLE>
<SMALL>
© <A HREF=mailto:morris@ee.uwa.edu.au>John Morris</A>, 1998
</SMALL>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?