Difference between revisions of "Aufgaben:Exercise 2.6: About the Huffman Coding"

From LNTwww
Line 3: Line 3:
 
}}
 
}}
  
[[File:EN_Inf_A_2_6_v2.png|right|frame|Tree diagram of the <br>HHuffman method]
+
[[File:EN_Inf_A_2_6_v2.png|right|frame|Tree diagram of the <br>Huffman method]]
 
We consider here a source symbol sequence&nbsp; $\langle q_\nu  \rangle$&nbsp; with symbol range&nbsp; $M = 8$:
 
We consider here a source symbol sequence&nbsp; $\langle q_\nu  \rangle$&nbsp; with symbol range&nbsp; $M = 8$:
 
:$$q_{\nu} = \{ \hspace{0.05cm}q_{\mu} \} = \{ \boldsymbol{\rm A} \hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm B}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm C}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm D}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm E}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm F}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm G}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm H}\hspace{0.05cm}
 
:$$q_{\nu} = \{ \hspace{0.05cm}q_{\mu} \} = \{ \boldsymbol{\rm A} \hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm B}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm C}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm D}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm E}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm F}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm G}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm H}\hspace{0.05cm}
 
\}\hspace{0.05cm}.$$
 
\}\hspace{0.05cm}.$$
If the symbols are equally probable, i.e.&nbsp; $p_{\rm A} =  p_{\rm B} =$ ... $ = p_{\rm H} = 1/M$then source coding makes no sense.&nbsp; Already with the dual code&nbsp; $\rm A$&nbsp; &#8594;&nbsp; <b>000</b>,&nbsp; $\rm B$&nbsp; &#8594;&nbsp; <b>001</b>, ... ,&nbsp; $\rm H$&nbsp; &#8594;&nbsp; <b>111</b>, the mean codeword length&nbsp; $L_{\rm M}$&nbsp; ihre untere Schranke&nbsp; $H$&nbsp; gemäß dem Quellencodierungstheorem&nbsp; $(H$ bezeichnet hierbei die <i>Quellenentropie</i>$)$:
+
If the symbols are equally probable, i.e.&nbsp; $p_{\rm A} =  p_{\rm B} =$ ... $ = p_{\rm H} = 1/M$ then source coding makes no sense.&nbsp; Already with the dual code&nbsp; $\rm A$&nbsp; &#8594;&nbsp; <b>000</b>,&nbsp; $\rm B$&nbsp; &#8594;&nbsp; <b>001</b>, ... ,&nbsp; $\rm H$&nbsp; &#8594;&nbsp; <b>111</b>, the mean codeword length&nbsp; $L_{\rm M}$&nbsp; is its lower bound&nbsp; $H$&nbsp; according to the source coding theorem&nbsp; $(H$ denotes the <i>source entropy</i>$ here)$:
:$$L_{\rm M,\hspace{0.08cm}min} = H = 3 \hspace{0.15cm}{\rm bit/Quellensymbol} \hspace{0.05cm}.$$
+
:$$L_{\rm M,\hspace{0.08cm}min} = H = 3 \hspace{0.15cm}{\rm bit/source symbol} \hspace{0.05cm}.$$
  
Die Symbolwahrscheinlichkeiten seien aber in dieser Aufgabe wie folgt gegeben:
+
However, let the symbol probabilities in this task be given as follows:
 
:$$p_{\rm A} \hspace{-0.05cm}= \hspace{-0.05cm} 0.04  \hspace{0.05cm},\hspace{0.1cm}p_{\rm B} \hspace{-0.05cm}= \hspace{-0.05cm} 0.08  \hspace{0.05cm},\hspace{0.1cm}p_{\rm C} \hspace{-0.05cm}= \hspace{-0.05cm} 0.14  \hspace{0.05cm},\hspace{0.1cm}
 
:$$p_{\rm A} \hspace{-0.05cm}= \hspace{-0.05cm} 0.04  \hspace{0.05cm},\hspace{0.1cm}p_{\rm B} \hspace{-0.05cm}= \hspace{-0.05cm} 0.08  \hspace{0.05cm},\hspace{0.1cm}p_{\rm C} \hspace{-0.05cm}= \hspace{-0.05cm} 0.14  \hspace{0.05cm},\hspace{0.1cm}
 
p_{\rm D} \hspace{-0.05cm}= \hspace{-0.05cm} 0.25  \hspace{0.05cm},\hspace{0.1cm} p_{\rm E} \hspace{-0.05cm}= \hspace{-0.05cm} 0.24  \hspace{0.05cm},\hspace{0.1cm}p_{\rm F} \hspace{-0.05cm}= \hspace{-0.05cm} 0.12  \hspace{0.05cm},\hspace{0.1cm}p_{\rm G} \hspace{-0.05cm}= \hspace{-0.05cm} 0.10  \hspace{0.05cm},\hspace{0.1cm}
 
p_{\rm D} \hspace{-0.05cm}= \hspace{-0.05cm} 0.25  \hspace{0.05cm},\hspace{0.1cm} p_{\rm E} \hspace{-0.05cm}= \hspace{-0.05cm} 0.24  \hspace{0.05cm},\hspace{0.1cm}p_{\rm F} \hspace{-0.05cm}= \hspace{-0.05cm} 0.12  \hspace{0.05cm},\hspace{0.1cm}p_{\rm G} \hspace{-0.05cm}= \hspace{-0.05cm} 0.10  \hspace{0.05cm},\hspace{0.1cm}
 
p_{\rm H} \hspace{-0.05cm}= \hspace{-0.05cm} 0.03  \hspace{0.05cm}.$$
 
p_{\rm H} \hspace{-0.05cm}= \hspace{-0.05cm} 0.03  \hspace{0.05cm}.$$
*Es liegt hier also eine redundante Nachrichtenquelle vor, die man durch Huffman&ndash;Codierung komprimieren kann.  
+
*So here we have a redundant message source that can be compressed by Huffman coding.
*Dieser Algorithmus wurde 1952 &ndash; also kurz nach Shannons bahnbrechenden Arbeiten zur Informationstheorie &ndash; von&nbsp; [https://de.wikipedia.org/wiki/David_A._Huffman David Albert Huffman]&nbsp; veröffentlicht und erlaubt die Konstruktion von optimalen präfixfreien Codes.
+
*This algorithm was published by&nbsp; [https://en.wikipedia.org/wiki/David_A._Huffman David Albert Huffman]&nbsp; &ndash; shortly after Shannon's groundbreaking work on information theory &ndash; and allows the construction of optimal prefix-free codes.
  
  
Der Algorithmus soll hier ohne Herleitung und Beweis angegeben werden, wobei wir uns auf Binärcodes beschränken &nbsp; &rArr; &nbsp; die Codesymbolfolge besteht nur aus Nullen und Einsen:
+
The algorithm is given here without derivation and proof, whereby we restrict ourselves to binary codes &nbsp; &rArr; &nbsp; the code symbol sequence consists only of zeros and ones:
  
:'''(1)''' &nbsp; Man ordne die Symbole nach fallenden Auftrittswahrscheinlichkeiten.
+
:'''(1)''' &nbsp; Order the symbols according to decreasing probabilities of occurrence.
  
:'''(2)''' &nbsp;  Man fasse die zwei unwahrscheinlichsten Symbole zu einem neuen Symbol zusammen.
+
:'''(2)''' &nbsp;  Combine the two least likely symbols into a new symbol.
  
:'''(3)''' &nbsp;  Man wiederhole Schritt&nbsp; '''(1)'''&nbsp; und&nbsp; '''(2)''', bis nur zwei (zusammengefasste) Symbole übrig bleiben.
+
:'''(3)''' &nbsp;  Repeat steps&nbsp; '''(1)'''&nbsp; and&nbsp; '''(2)''', until only two (combined) symbols remain.
  
:'''(4)''' &nbsp;  Die wahrscheinlichere Symbolmenge wird mit&nbsp; <b>1</b>&nbsp; binär codiert, die andere Menge mit&nbsp; <b>0</b>.
+
:'''(4)''' &nbsp;  Binary code the more probable set of symbols with&nbsp; <b>1</b>&nbsp;, the other set with&nbsp; <b>0</b>.
  
:'''(5)''' &nbsp;  Man ergänze schrittweise (von unten nach oben) die aufgespaltenen Teilcodes mit&nbsp; <b>1</b>&nbsp; bzw.&nbsp; <b>0</b>.
+
:'''(5)''' &nbsp;  Step by step (from bottom to top) add&nbsp; <b>1</b>&nbsp; or&nbsp; <b>0</b> to the split partial codes.
  
  
Oft wird dieser Algorithmus durch ein Baumdiagramm veranschaulicht. Die obige Grafik zeigt dieses für den vorliegenden Fall.  
+
This algorithm is often illustrated by a tree diagram. The diagram above shows this for the case at hand.
  
Sie haben folgende Aufgaben:
+
You have the following tasks:
  
:'''(a)''' &nbsp; Zuordnung der Symbole&nbsp; $\rm A$, ... , $\rm H$&nbsp; zu den mit&nbsp; '''[1]''', ... , '''[8]'''&nbsp; bezeichneten Eingängen.
+
:'''(a)''' &nbsp; Assign the symbols&nbsp; $\rm A$, ... , $\rm H$&nbsp; to the inputs labelled&nbsp; '''[1]''', ... , '''[8]'''&nbsp;.
  
:'''(b)''' &nbsp; Bestimmung der Summenwahrscheinlichkeiten&nbsp; $U$, ... ,&nbsp; $Z$&nbsp; sowie&nbsp; $R$&nbsp; (<i>Root</i>).
+
:'''(b)''' &nbsp; Determination of the sum probabilities&nbsp; $U$, ... ,&nbsp; $Z$&nbsp; and&nbsp; $R$&nbsp; (<i>root</i>).
  
:'''(c)''' &nbsp; Zuordnung der Symbole&nbsp; $\rm A$, ... ,&nbsp; $\rm H$&nbsp; zu den entsprechenden Huffman&ndash;Binärfolgen. Eine rote Verbindung entspricht einer&nbsp; <b>1</b>, eine blaue Verbindung einer&nbsp; <b>0</b>.
+
:'''(c)''' &nbsp; Assignment of the symbols&nbsp; $\rm A$, ... ,&nbsp; $\rm H$&nbsp; to the corresponding Huffman binary sequences. A red connection corresponds to a&nbsp; <b>1</b>, a blue connection to a&nbsp; <b>0</b>.
  
Sie werden feststellen, dass die mittlere Codewortlänge
+
You will notice that the mean codeword length is
 
:$$L_{\rm M} =  \sum_{\mu = 1}^{M}\hspace{0.05cm} p_{\mu} \cdot L_{\mu} $$
 
:$$L_{\rm M} =  \sum_{\mu = 1}^{M}\hspace{0.05cm} p_{\mu} \cdot L_{\mu} $$
bei Huffman&ndash;Codierung nur unwesentlich größer ist als die Quellenentropie&nbsp; $H$.&nbsp; In dieser Gleichung gelten für den vorliegenden Fall folgende Werte:  
+
for Huffman coding is only slightly larger than the source entropy&nbsp; $H$.&nbsp; IIn this equation, the following values apply to the present case:
 
*$M = 8$,&nbsp;  $p_1 = p_{\rm A}$,&nbsp; ... ,&nbsp; $p_8 = p_{\rm H}$.  
 
*$M = 8$,&nbsp;  $p_1 = p_{\rm A}$,&nbsp; ... ,&nbsp; $p_8 = p_{\rm H}$.  
*Die jeweilige Bitanzahl der Codesymbole für&nbsp; $\rm A$, ... ,&nbsp; $\rm H$&nbsp; ist mit&nbsp; $L_1$, ... ,&nbsp; $L_8$&nbsp; bezeichnet.
+
*The respective number of bits of the code symbols for&nbsp; $\rm A$, ... ,&nbsp; $\rm H$&nbsp; is denoted by&nbsp; $L_1$, ... ,&nbsp; $L_8$&nbsp;.
  
  
Line 53: Line 53:
  
  
''Hinweise:''  
+
''Hints:''  
*Die Aufgabe gehört zum  Kapitel&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman|Entropiecodierung nach Huffman]].
+
*The exercise belongs to the chapter&nbsp; [[Information_Theory/Entropiecodierung_nach_Huffman|Entropy Coding according to Huffman]].
*Insbesondere wird  Bezug genommen auf die Seiten&nbsp;
+
*In particular, reference is made to the pages&nbsp;
** [[Information_Theory/Entropiecodierung_nach_Huffman#Der_Huffman.E2.80.93Algorithmus|Der Huffman-Algorithmus]],
+
** [[Information_Theory/Entropiecodierung_nach_Huffman#The_Huffman_algorithm|The Huffman algorithm]],
**[[Information_Theory/Entropiecodierung_nach_Huffman#Darstellung_des_Huffman.E2.80.93Codes_als_Baumdiagramm|Darstellung des Huffman-Codes als Baumdiagramm]].
+
**[[Information_Theory/Entropiecodierung_nach_Huffman#Representation_of_the_Huffman_code_as_a_tree_diagram|Representation of the Huffman code as a tree diagram]].
*Zur Kontrolle Ihrer Ergebnisse verweisen wir auf das Interaktionsmodul&nbsp; [[Applets:Huffman-_und_Shannon-Fano-Codierung|Shannon&ndash;Fano&ndash; und Huffman&ndash;Codierung]].
+
*To check your results, please refer to the interaction module&nbsp; [[Applets:Huffman-_und_Shannon-Fano-Codierung|Shannon&ndash;Fano&ndash; and Huffman&ndash;coding]].
 
   
 
   
  
  
===Fragebogen===
+
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche Eingänge im Baumdiagramm stehen für
+
{Which inputs in the tree diagram stand for
 
|type="{}"}
 
|type="{}"}
Eingangsnummer $ \ = \ $  { 7 } &nbsp; &rArr; &nbsp; Symbol $\rm A$  
+
Input number $ \ = \ $  { 7 } &nbsp; &rArr; &nbsp; symbol $\rm A$  
Eingangsnummer $ \ = \ $  { 6 } &nbsp; &rArr; &nbsp; Symbol $\rm B$
+
Input number $ \ = \ $  { 6 } &nbsp; &rArr; &nbsp; symbol $\rm B$
Eingangsnummer $ \ = \ $  { 3 } &nbsp; &rArr; &nbsp; Symbol $\rm C$
+
Input number $ \ = \ $  { 3 } &nbsp; &rArr; &nbsp; symbol $\rm C$
Eingangsnummer $ \ = \ $  { 1 } &nbsp; &rArr; &nbsp; Symbol $\rm D$
+
Input number $ \ = \ $  { 1 } &nbsp; &rArr; &nbsp; symbol $\rm D$
  
  
{Welche Zahlenwerte (Wahrscheinlichkeiten) sollten bei den Knoten im Baumdiagramm stehen?
+
{What numerical values (probabilities) should be at the nodes in the tree diagram?
 
|type="{}"}
 
|type="{}"}
Wahrscheinlichkeit $ \ = \ $ { 0.07 1% } &nbsp; bei Knoten $\rm U$
+
Probability $ \ = \ $ { 0.07 1% } &nbsp; at node $\rm U$
Wahrscheinlichkeit $ \ = \ $ { 0.15 1% } &nbsp; bei Knoten $\rm V$
+
Probability $ \ = \ $ { 0.15 1% } &nbsp; at node $\rm V$
Wahrscheinlichkeit $ \ = \ $ { 0.22 1% } &nbsp; bei Knoten $\rm W$
+
Probability $ \ = \ $ { 0.22 1% } &nbsp; at node $\rm W$
Wahrscheinlichkeit $ \ = \ $ { 0.29 1% } &nbsp; bei Knoten $\rm X$
+
Probability $ \ = \ $ { 0.29 1% } &nbsp; at node $\rm X$
Wahrscheinlichkeit $ \ = \ $ { 0.46 1% } &nbsp; bei Knoten $\rm Y$
+
Probability $ \ = \ $ { 0.46 1% } &nbsp; at node $\rm Y$
Wahrscheinlichkeit $ \ = \ $ { 0.54 1% } &nbsp; bei Knoten $\rm Z$
+
Probability $ \ = \ $ { 0.54 1% } &nbsp; at node $\rm Z$
Wahrscheinlichkeit $ \ = \ $ { 1 1% } &nbsp; bei $\rm Root$
+
Probability $ \ = \ $ { 1 1% } &nbsp; at $\rm root$
  
  
  
{Welche Binärcodes (darzustellen mit Nullen und Einsen) ergeben sich für
+
{Which binary codes (represented with zeros and ones) result for
 
|type="{}"}
 
|type="{}"}
Binärcode $ \ = \ $ { 11101 } &nbsp; &rArr; &nbsp; Symbol $\rm A$  
+
Binary code $ \ = \ $ { 11101 } &nbsp; &rArr; &nbsp; symbol $\rm A$  
Binärcode $ \ = \ $ { 1111 } &nbsp; &rArr; &nbsp; Symbol $\rm B$  
+
Binary code $ \ = \ $ { 1111 } &nbsp; &rArr; &nbsp; symbol $\rm B$  
Binärcode $ \ = \ $ { 110 } &nbsp; &rArr; &nbsp; Symbol $\rm C$  
+
Binary code $ \ = \ $ { 110 } &nbsp; &rArr; &nbsp; symbol $\rm C$  
Binärcode $ \ = \ $ { 10 } &nbsp; &rArr; &nbsp; Symbol $\rm D$  
+
Binary code $ \ = \ $ { 10 } &nbsp; &rArr; &nbsp; symbol $\rm D$  
  
  
{Wie groß ist die mittlere Codewortlänge?
+
{What is the mean codeword length?
 
|type="{}"}
 
|type="{}"}
$L_{\rm M} \ = \ $  { 2.73 3% } $\ \rm bit/Quellensymbol$
+
$L_{\rm M} \ = \ $  { 2.73 3% } $\ \rm bit/source symbol$
  
  
{Wie groß ist die Quellenentropie&nbsp; $H$?  
+
{What is the source entropy&nbsp; $H$?  
 
|type="()"}
 
|type="()"}
+ $H = 2.71\ \rm  bit/Quellensymbol.$
+
+ $H = 2.71\ \rm  bit/source symbol.$
- $H = 2.75\ \rm  bit/Quellensymbol.$
+
- $H = 2.75\ \rm  bit/source symbol.$
- $H = 3.00\ \rm  bit/Quellensymbol.$
+
- $H = 3.00\ \rm  bit/source symbol.$
  
  
Line 108: Line 108:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
 
'''(1)'''&nbsp; Vor dem Huffman&ndash;Algorithmus müssen die Symbole nach ihren Auftrittswahrscheinlichkeiten sortiert werden.  
 
'''(1)'''&nbsp; Vor dem Huffman&ndash;Algorithmus müssen die Symbole nach ihren Auftrittswahrscheinlichkeiten sortiert werden.  

Revision as of 22:25, 2 August 2021

Tree diagram of the
Huffman method

We consider here a source symbol sequence  $\langle q_\nu \rangle$  with symbol range  $M = 8$:

$$q_{\nu} = \{ \hspace{0.05cm}q_{\mu} \} = \{ \boldsymbol{\rm A} \hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm B}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm C}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm D}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm E}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm F}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm G}\hspace{0.05cm},\hspace{0.05cm} \boldsymbol{\rm H}\hspace{0.05cm} \}\hspace{0.05cm}.$$

If the symbols are equally probable, i.e.  $p_{\rm A} = p_{\rm B} =$ ... $ = p_{\rm H} = 1/M$ then source coding makes no sense.  Already with the dual code  $\rm A$  →  000,  $\rm B$  →  001, ... ,  $\rm H$  →  111, the mean codeword length  $L_{\rm M}$  is its lower bound  $H$  according to the source coding theorem  $(H$ denotes the source entropy$ here)$:

$$L_{\rm M,\hspace{0.08cm}min} = H = 3 \hspace{0.15cm}{\rm bit/source symbol} \hspace{0.05cm}.$$

However, let the symbol probabilities in this task be given as follows:

$$p_{\rm A} \hspace{-0.05cm}= \hspace{-0.05cm} 0.04 \hspace{0.05cm},\hspace{0.1cm}p_{\rm B} \hspace{-0.05cm}= \hspace{-0.05cm} 0.08 \hspace{0.05cm},\hspace{0.1cm}p_{\rm C} \hspace{-0.05cm}= \hspace{-0.05cm} 0.14 \hspace{0.05cm},\hspace{0.1cm} p_{\rm D} \hspace{-0.05cm}= \hspace{-0.05cm} 0.25 \hspace{0.05cm},\hspace{0.1cm} p_{\rm E} \hspace{-0.05cm}= \hspace{-0.05cm} 0.24 \hspace{0.05cm},\hspace{0.1cm}p_{\rm F} \hspace{-0.05cm}= \hspace{-0.05cm} 0.12 \hspace{0.05cm},\hspace{0.1cm}p_{\rm G} \hspace{-0.05cm}= \hspace{-0.05cm} 0.10 \hspace{0.05cm},\hspace{0.1cm} p_{\rm H} \hspace{-0.05cm}= \hspace{-0.05cm} 0.03 \hspace{0.05cm}.$$
  • So here we have a redundant message source that can be compressed by Huffman coding.
  • This algorithm was published by  David Albert Huffman  – shortly after Shannon's groundbreaking work on information theory – and allows the construction of optimal prefix-free codes.


The algorithm is given here without derivation and proof, whereby we restrict ourselves to binary codes   ⇒   the code symbol sequence consists only of zeros and ones:

(1)   Order the symbols according to decreasing probabilities of occurrence.
(2)   Combine the two least likely symbols into a new symbol.
(3)   Repeat steps  (1)  and  (2), until only two (combined) symbols remain.
(4)   Binary code the more probable set of symbols with  1 , the other set with  0.
(5)   Step by step (from bottom to top) add  1  or  0 to the split partial codes.


This algorithm is often illustrated by a tree diagram. The diagram above shows this for the case at hand.

You have the following tasks:

(a)   Assign the symbols  $\rm A$, ... , $\rm H$  to the inputs labelled  [1], ... , [8] .
(b)   Determination of the sum probabilities  $U$, ... ,  $Z$  and  $R$  (root).
(c)   Assignment of the symbols  $\rm A$, ... ,  $\rm H$  to the corresponding Huffman binary sequences. A red connection corresponds to a  1, a blue connection to a  0.

You will notice that the mean codeword length is

$$L_{\rm M} = \sum_{\mu = 1}^{M}\hspace{0.05cm} p_{\mu} \cdot L_{\mu} $$

for Huffman coding is only slightly larger than the source entropy  $H$.  IIn this equation, the following values apply to the present case:

  • $M = 8$,  $p_1 = p_{\rm A}$,  ... ,  $p_8 = p_{\rm H}$.
  • The respective number of bits of the code symbols for  $\rm A$, ... ,  $\rm H$  is denoted by  $L_1$, ... ,  $L_8$ .




Hints:


Questions

1

Which inputs in the tree diagram stand for

Input number $ \ = \ $

  ⇒   symbol $\rm A$
Input number $ \ = \ $

  ⇒   symbol $\rm B$
Input number $ \ = \ $

  ⇒   symbol $\rm C$
Input number $ \ = \ $

  ⇒   symbol $\rm D$

2

What numerical values (probabilities) should be at the nodes in the tree diagram?

Probability $ \ = \ $

  at node $\rm U$
Probability $ \ = \ $

  at node $\rm V$
Probability $ \ = \ $

  at node $\rm W$
Probability $ \ = \ $

  at node $\rm X$
Probability $ \ = \ $

  at node $\rm Y$
Probability $ \ = \ $

  at node $\rm Z$
Probability $ \ = \ $

  at $\rm root$

3

Which binary codes (represented with zeros and ones) result for

Binary code $ \ = \ $

  ⇒   symbol $\rm A$
Binary code $ \ = \ $

  ⇒   symbol $\rm B$
Binary code $ \ = \ $

  ⇒   symbol $\rm C$
Binary code $ \ = \ $

  ⇒   symbol $\rm D$

4

What is the mean codeword length?

$L_{\rm M} \ = \ $

$\ \rm bit/source symbol$

5

What is the source entropy  $H$?

$H = 2.71\ \rm bit/source symbol.$
$H = 2.75\ \rm bit/source symbol.$
$H = 3.00\ \rm bit/source symbol.$


Solution

(1)  Vor dem Huffman–Algorithmus müssen die Symbole nach ihren Auftrittswahrscheinlichkeiten sortiert werden.

  • Da die zwei unwahrscheinlichsten Symbole schon im ersten Schritt zusammengefasst werden, nehmen die Auftrittswahrscheinlichkeiten von oben nach unten ab
    (in der Grafik zu dieser Musterlösung von links nach rechts).
  • Durch Vergleich mit dem Angabenblatt erhält man:
Symbol $\rm A$:  Eingang 7,     Symbol $\rm B$:  Eingang 6,     Symbol $\rm C$:  Eingang 3,     Symbol $\rm D$:  Eingang 1.
An die Aufgabe angepasstes Baumdiagramm

P_ID2452__Inf_A_2_6a.png


(2)  Der Knoten  $\rm R$  ist die Baumwurzel  (Root).  Dieser ist stets mit  $\underline{R=1}$  belegt, unabhängig von den Auftrittswahrscheinlichkeiten.

Für die weiteren Werte gilt:

Schritt 1:    $p_{\rm U} = p_{\rm A} + p_{\rm H} = 0.04 + 0.03 \hspace{0.15cm}\underline{ =0.07}$,
Schritt 2:    $p_{\rm V} = p_{\rm U} + p_{\rm B} = 0.07 + 0.08 \hspace{0.15cm}\underline{ =0.15}$,
Schritt 3:    $p_{\rm W} = p_{\rm F} + p_{\rm G} = 0.12 + 0.10 \hspace{0.15cm}\underline{ =0.22}$,
Schritt 4:    $p_{\rm X} = p_{\rm V} + p_{\rm C} = 0.15 + 0.14 \hspace{0.15cm}\underline{ =0.29}$,
Schritt 5:    $p_{\rm Y} = p_{\rm W} + p_{\rm E} = 0.22 + 0.24 \hspace{0.15cm}\underline{ =0.46}$,
Schritt 6:    $p_{\rm Z} = p_{\rm X} + p_{\rm D} = 0.29 + 0.25 \hspace{0.15cm}\underline{ =0.54}$.


(3)  Den Huffman–Code für das Symbol  $\rm A$  erhält man, wenn man den Weg von der  $\rm Root$  (gelber Punkt) zum Symbol  $\rm A$  zurückverfolgt und jeder roten Verbindungslinie eine  1  zuordnet, jeder blauen eine  0.

  • Symbol $\rm A$:    rot–rot–rot–blau–rot → 11101,
  • Symbol $\rm B$:    rot–rot–rot–rot → 1111,
  • Symbol $\rm C$:    rot–rot–blau → 110,
  • Symbol $\rm D$:    rot–blau– → 10,
  • Symbol $\rm E$:    blau–rot → 01,
  • Symbol $\rm F$:    blau–blau–rot → 001,
  • Symbol $\rm G$:    blau–blau–blau → 000,
  • Symbol $\rm H$:    rot–rot–rot–blau–blau → 11100.


(4)  Die Codierung unter Punkt  (3)  hat ergeben, dass

  • die Symbole  $\rm D$  und  $\rm E$  mit zwei Bit,
  • die Symbole  $\rm C$,  $\rm F$  und  $\rm G$  mit drei Bit,
  • das Symbol  $\rm B$  mit vier Bit,  und
  • die Symbole  $\rm A$  und  $\rm H$  jeweils mit fünf Bit


dargestellt werden.  Damit erhält man für die mittlere Codewortlänge (in "bit/Quellensymbol&dquo;):

$$L_{\rm M} \hspace{0.2cm} = \hspace{0.2cm} (p_{\rm D} + p_{\rm E}) \cdot 2 + (p_{\rm C} + p_{\rm F} + p_{\rm G}) \cdot 3 + p_{\rm B} \cdot 4 +(p_{\rm A} + p_{\rm H}) \cdot 5 = 0.49 \cdot 2 + 0.36 \cdot 3 +0.08 \cdot 4 +0.07 \cdot 5 \hspace{0.15cm}\underline{= 2.73}\hspace{0.05cm}.$$


(5)  Richtig ist allein die Antwort 1:

  • Die mittlere Codewortlänge  $L_{\rm M}$  kann nicht kleiner sein als die Quellenentropie  $H$.  Damit scheiden die Antworten 2 und 3 aus.
  • Aus den vorgegebenen Auftrittswahrscheinlichkeiten kann die Quellenentropie tatsächlich zu  $H = 2.71$ bit/Quellensymbol berechnet werden.
  • Man erkennt, dass diese Huffman–Codierung die vorgegebene Grenze  (Quellencodierungstheorem)  $L_{\rm M, \ min } \ge H = 2.71$  bit/Quellensymbol nahezu erreicht.