Difference between revisions of "Aufgaben:Exercise 2.2: Kraft–McMillan Inequality"

From LNTwww
 
(28 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Informationstheorie/Allgemeine Beschreibung
+
{{quiz-Header|Buchseite=Information_Theory/General_Description
 
}}
 
}}
  
[[File:P_ID2416__Inf_A_2_2.png|right|]]
+
[[File:P_ID2416__Inf_A_2_2.png|right|frame|Four examples of binary codes and three ternary codes]]
:In der rechten Abbildung sind einige beispielhafte Binär– und Ternärcodes angegeben.
+
In the figure some exemplary binary and ternary codes are given.
  
:Beim Binärcode B1 werden alle möglichen Quellensymbole <i>q<sub>&mu;</sub></i> (mit Laufindex <i>&mu;</i> = 1, ... , 8) durch jeweils eine Codesymbolfolge &#9001;<i>c<sub>&mu;</sub></i>&#9002; einheitlicher Länge <i>L<sub>&mu;</sub></i> = 3 dargestellt. Dieser Code ist aus diesem Grund zur Datenkomprimierung ungeeignet.
+
*With the  binary code&nbsp; $\rm B1$&nbsp; all possible source symbols&nbsp; $q_\mu$&nbsp; $($with index&nbsp; $\mu = 1$, ... , $8)$&nbsp; are represented by a encoded sequence&nbsp; $\langle c_\mu \rangle $&nbsp; of uniform length&nbsp; $L_\mu = 3$&nbsp;.  
 +
*This code is unsuitable for data compression for this reason.
  
:Die Möglichkeit zur Datenkomprimierung ergibt sich erst dann, wenn
 
  
:* die <i>M</i> Quellensymbole nicht gleichwahrscheinlich sind,
+
The possibility of data compression arises only when
 +
*the&nbsp; $M$&nbsp; source symbols are not equally likely, and
 +
*the length&nbsp; $L_\mu$&nbsp; of the code words are different.
  
:* und die Länge <i>L<sub>&mu;</sub></i> der Codeworte unterschiedlich sind.
 
  
:Diese Eigenschaft weist zum Beispiel der Binärcode B2 auf: Je ein Codewort hat hier die Länge 1, 2 und 3 (<i>N</i><sub>1</sub> = <i>N</i><sub>2</sub> = <i>N</i><sub>3</sub> = 1) und zwei Codeworte haben die Länge <i>L<sub>&mu;</sub></i> = 4 (<i>N</i><sub>4</sub> = 2).
+
For example, the binary code&nbsp;  $\rm B2$&nbsp; has this property:   &nbsp;
 +
*Here, one code word each has the length &nbsp; $1$,&nbsp; $2$&nbsp; and&nbsp; $3$, respectively&nbsp; $(N_1 = 1,\ N_2 = 2,\ N_3 = 3)$.
 +
*Two code words have the length&nbsp; $L_\mu = 4$&nbsp; $(N_4 = N_5 = 4)$.
  
:Voraussetzung für die Decodierbarkeit eines solchen Codes ist, dass der Code präfixfrei ist.  Das heißt, dass kein Codewort der Präfix (der Beginn) eines längeren Codewortes sein darf.
 
  
:Eine notwendige Bedingung dafür, dass ein Code zur Datenkomprimierung präfixfrei sein kann, wurde 1949 von Leon Kraft angegeben, die Kraftsche Ungleichung:
+
A prerequisite for the decodability of such a code is that the code is&nbsp; '''prefix-free'''&nbsp;.&nbsp; 
 +
*That is, no code word may be the prefix (i.e., the beginning) of a longer code word.
 +
 
 +
*A necessary condition for a code  for data compression to be prefix-free was stated by Leon Kraft in 1949, called&nbsp;  '''Kraft's inequality''':
 
:$$\sum_{\mu=1}^{M} \hspace{0.2cm} D^{-L_{\mu}} \le 1 \hspace{0.05cm}.$$
 
:$$\sum_{\mu=1}^{M} \hspace{0.2cm} D^{-L_{\mu}} \le 1 \hspace{0.05cm}.$$
:Hierbei bezeichnen
 
  
:* <i>M</i> die Anzahl der möglichen Quellensymbole <i>q<sub>&mu;</sub></i>,
+
Here denote
 +
* $M$&nbsp; the number of possible source symbols&nbsp; $q_\mu$ &nbsp; &rArr; &nbsp; "symbol set size",
 +
* $L_\mu$&nbsp; the length of the code word&nbsp; $c_\mu$&nbsp; associated with the source symbol&nbsp;  $q_\mu$,
 +
* $D = 2$&nbsp; denotes a binary code&nbsp; $(\rm 0$&nbsp;  or&nbsp; $\rm 1)$&nbsp; and&nbsp; $D = 3$&nbsp; denotes a ternary code&nbsp; $(\rm 0$,&nbsp; $\rm 1$,&nbsp; $\rm 2)$.
  
:* <i>L<sub>&mu;</sub></i> die Länge des zum Quellensymbol <i>q<sub>&mu;</sub></i> gehörigen Codewortes  <i>c<sub>&mu;</sub></i>,
 
  
:* <i>D</i> = 2 einen Binärcode (<b>0</b> oder <b>1</b>) und <i>D</i> = 3 einen Ternärcode (<b>0</b>, <b>1</b>, <b>2</b>).
+
A code can be prefix-free only if Kraft's inequality is satisfied.&nbsp;
  
:Ein Code kann nur dann präfixfrei sein, wenn die Kraftsche Ungleichung erfüllt ist. Die Umkehrung gilt nicht: Wird die Kraftsche Ungleichung erfüllt, so bedeutet das noch lange nicht, dass dieser Code tatsächlich präfixfrei ist.
+
The converse does not hold: &nbsp; If Kraft's inequality is satisfied, it does not mean that this code is actually prefix-free.
  
:<b>Hinweis:</b> Die Aufgabe bezieht sich auf das Kapitel 2.1.
 
  
  
===Fragebogen===
+
 
 +
Hint:
 +
*The exercise belongs to the chapter&nbsp; [[Information_Theory/Allgemeine_Beschreibung|General Description of Source Coding]].
 +
 +
 
 +
 
 +
===Question===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche der Binärcodes erfüllen die Kraftsche Ungleichung?
+
{Which of the binary codes satisfy Kraft's inequality?
 
|type="[]"}
 
|type="[]"}
+ B1,
+
+ $\rm B1$,
+ B2,
+
+ $\rm B2$,
- B3,
+
+ $\rm B3$,
- B4.
+
- $\rm B4$.
  
  
{Welche der vorgegebenen Binärcodes sind präfixfrei?
+
{Which of the given binary codes are prefix-free?
 
|type="[]"}
 
|type="[]"}
+ B1,
+
+ $\rm B1$,
+ B2,
+
+ $\rm B2$,
- B3,
+
- $\rm B3$,
- B4.
+
- $\rm B4$.
  
  
{Welche der vorgegebenen Ternärcodes sind präfixfrei?
+
{Which of the given ternary codes are prefix-free?
 
|type="[]"}
 
|type="[]"}
+ T1,
+
+ $\rm T1$,
- T2,
+
- $\rm T2$,
+ T3.
+
+ $\rm T3$.
  
  
{Wie lauten die Kenngrößen des Codes T1?
+
{What are the characteristics of the ternary code&nbsp; $\rm T1$?
 
|type="{}"}
 
|type="{}"}
$Ternärecode\ T1:\ \ N_1$ = { 1 3% }
+
$ N_1 \ = \ $ { 1 }
$N_2$ = { 2 3% }
+
$ N_2 \ = \ $ { 2 }
$N_3$ = { 6 3% }
+
$ N_3 \ = \ $ { 6 }
 +
 
  
  
{Wieviel 3&ndash;wertige Codeworte (<i>L<sub>&mu;</sub></i> = 3) könnte man hinzufügen, ohne dass sich an der Präfixfreiheit etwas ändert?
+
{How many trivalent code words&nbsp; $(L_\mu = 3)$&nbsp; could be added to the&nbsp; $\rm T1$&nbsp; code without changing the prefix freedom?
 
|type="{}"}
 
|type="{}"}
$Ternärecode\ \Delta N_3:\ \ N_1$ = { 6 3% }
+
$\Delta N_3 \ = \ $ { 6 }
  
  
{Der Ternärcode T3 soll auf insgesamt <i>N</i> = 9 Codeworte erweitert werden. Wie erreicht man das ohne Verletzung der Präfixfreiheit?
+
{The ternary code&nbsp; $\rm T3$&nbsp; is to be expanded to a total of&nbsp; $N = 9$&nbsp; code words.&nbsp; How to achieve this without violating the prefix freedom?
 
|type="[]"}
 
|type="[]"}
- Ergänzung um vier 3&ndash;wertige Codeworte.
+
- Addition of four three-valued code words.
+ Ergänzung um vier 4&ndash;wertige Codeworte.
+
+ Addition of four four-valued code words.
+ Ergänzung um ein 3&ndash;wertiges und drei 4&ndash;wertige Codeworte.
+
+ Addition of one trivalent and three tetravalent code words.
  
  
Line 81: Line 93:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Für die angegebenen Binärcodes gilt:
+
'''(1)'''&nbsp; The correct <u>solutions are 1, 2 and 3.</u>&nbsp; The following applies to the binary codes given:
 +
* $\rm B1$:&nbsp;&nbsp;&nbsp; $8 \cdot 2^{-3} = 1$ &nbsp;&nbsp;&#8658;&nbsp;&nbsp; condition fulfilled,
 +
* $\rm B2$:&nbsp;&nbsp;&nbsp; $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 1 \cdot 2^{-3}  + 2 \cdot 2^{-4}= 1$ &nbsp;&nbsp;&#8658;&nbsp;&nbsp; condition fulfilled,
 +
* $\rm B3$:&nbsp;&nbsp;&nbsp; $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 1 \cdot 2^{-3}  + 2 \cdot 2^{-4}= 1$ &nbsp;&nbsp;&#8658;&nbsp;&nbsp; condition fulfilled,
 +
* $\rm B4$:&nbsp;&nbsp;&nbsp; $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 2 \cdot 2^{-3}  + 1 \cdot 2^{-4}= 17/16$ &nbsp;&nbsp;&#8658;&nbsp;&nbsp; condition <u>not</u> fulfilled.
 +
 
  
:* B1:&nbsp;&nbsp;&nbsp; 8 &middot; 2<sup>&ndash;3</sup> = 1 &nbsp;&nbsp;&#8658;&nbsp;&nbsp; Bedingung erfüllt,
 
  
:* B2:&nbsp;&nbsp;&nbsp; 1 &middot; 2<sup>&ndash;1</sup> + 1 &middot; 2<sup>&ndash;2</sup> + 1 &middot; 2<sup>&ndash;3</sup> + 2 &middot; 2<sup>&ndash;4</sup> = 1 &nbsp;&nbsp;&#8658;&nbsp;&nbsp; Bedingung erfüllt,
+
'''(2)'''&nbsp; <u>Proposed solutions 1 and 2</u> are correct:
 +
*The code&nbsp; $\rm B4$, which does not satisfy Kraft's inequality, is certainly not prefix-free either.
 +
*But if Kraft's inequality is fulfilled, it is still not certain that this code is also prefix-free.
 +
*In code&nbsp; $\rm B3$&nbsp; the code word&nbsp; "10"&nbsp; is the beginning of the code word&nbsp; "1011".
 +
*In contrast, codes&nbsp; $\rm B1$&nbsp; and&nbsp; $\rm B2$&nbsp; are actually prefix-free.
  
:* B3:&nbsp;&nbsp;&nbsp; 1 &middot; 2<sup>&ndash;1</sup> + 1 &middot; 2<sup>&ndash;2</sup> + 1 &middot; 2<sup>&ndash;3</sup> + 2 &middot; 2<sup>&ndash;4</sup> = 1 &nbsp;&nbsp;&#8658;&nbsp;&nbsp; Bedingung erfüllt,
 
  
:* B4:&nbsp;&nbsp;&nbsp;  1 &middot; 2<sup>&ndash;1</sup> + 1 &middot; 2<sup>&ndash;2</sup> + 2 &middot; 2<sup>&ndash;3</sup> + 1 &middot; 2<sup>&ndash;4</sup> = 17/16 &nbsp;&nbsp;&#8658;&nbsp;&nbsp; Bedingung <u>nicht</u> erfüllt.
 
  
:<b>2.</b>&nbsp;&nbsp;Der Code B4, der die Kraftsche Ungleichung nicht erfüllt, ist mit Sicherheit auch nicht präfixfrei. Aber bei Erfüllung der Kraftschen Ungleichung ist noch nicht sicher, dass dieser Code auch präfixfrei ist. Beim Code B3 ist &bdquo;10&rdquo; der Beginn des Codewortes &bdquo;1011&rdquo;. Dagegen sind die Codes <u>B1 und B2</u> präfixfrei.
+
'''(3)'''&nbsp; The correct <u>solutions are 1 and 3</u>:
 +
*Kraft's inequality is satisfied by all three codes.
 +
*As can be seen from the table, codes&nbsp; $\rm T1$&nbsp; and&nbsp; $\rm T3$&nbsp; are indeed prefix-free.
 +
*The code&nbsp; $\rm T2$&nbsp;, on the other hand, is not prefix-free because "1" is the beginning of the code word "10".
  
:<b>3.</b>&nbsp;&nbsp;Richtig sind die <u>Antworten 1 und 3</u>. Der Code T2 ist dagegen nicht präfixfrei, da &bdquo;1&rdquo; der Beginn des Codewortes &bdquo;10&rdquo; ist. Die Kraftsche Ungleichung wird von allen drei Codes erfüllt.
 
  
:<b>4.</b>&nbsp;&nbsp;<i>N<sub>i</sub></i> gibt an, wieviele Codeworte  mit <i>i</i> Symbolen  es im Code gibt. Für den Code T1 gilt:
+
 
 +
'''(4)'''&nbsp; $N_i$&nbsp; indicates how many code words with&nbsp; $i$&nbsp; symbols there are in the code.&nbsp; For the code&nbsp; $\rm T1$&nbsp; it is:
 
:$$N_1 \hspace{0.15cm}\underline{= 1}\hspace{0.05cm}, \hspace{0.2cm}N_2 \hspace{0.15cm}\underline{= 2}\hspace{0.05cm}, \hspace{0.2cm}N_3 \hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$
 
:$$N_1 \hspace{0.15cm}\underline{= 1}\hspace{0.05cm}, \hspace{0.2cm}N_2 \hspace{0.15cm}\underline{= 2}\hspace{0.05cm}, \hspace{0.2cm}N_3 \hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$
  
:<b>5.</b>&nbsp;&nbsp;Nach der Kraftschen Ungleichung muss gelten
+
 
 +
 
 +
'''(5)'''&nbsp; According to Kraft's inequality, the following must be true
 
:$$N_1 \cdot 3^{-1} + N_2 \cdot 3^{-2} + N_3 \cdot 3^{-3 } \le 1\hspace{0.05cm}.$$
 
:$$N_1 \cdot 3^{-1} + N_2 \cdot 3^{-2} + N_3 \cdot 3^{-3 } \le 1\hspace{0.05cm}.$$
:Bei gegebenem <i>N</i><sub>1</sub> = 1 und <i>N</i><sub>2</sub> = 2 wird dies erfüllt, solange gilt:
+
For given&nbsp; $N_1 = 1$&nbsp; and&nbsp;  $N_2 = 2$&nbsp; , this is satisfied as long as holds:
 
:$$N_3 \cdot 3^{-3 } \le 1 - 1/3 - 2/9 = 4/9 \hspace{0.3cm} \Rightarrow \hspace{0.3cm}N_3  \le 12 \hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm \Delta}\,N_3
 
:$$N_3 \cdot 3^{-3 } \le 1 - 1/3 - 2/9 = 4/9 \hspace{0.3cm} \Rightarrow \hspace{0.3cm}N_3  \le 12 \hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm \Delta}\,N_3
 
\hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$
 
\hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$
:Die zusätzlichen Codeworte sind <b>210</b>, <b>211</b>, <b>212</b>, <b>220</b>, <b>221</b> und <b>222</b>.
+
The additional code words are&nbsp; $\rm 210, \,211, \,212, \,220, \,221, \,222$.
 +
 
  
:<b>6.</b>&nbsp;&nbsp;Für den Code T3 gilt:
 
:$$S({\rm T3})= 2 \cdot 3^{-1} + 2 \cdot 3^{-2} + 1 \cdot 3^{-3 } = {25}/{27}\hspace{0.05cm}.$$
 
:Wegen <i>S</i>(T3) &#8804; 1 erfüllt der Ternärcode T3 die Kraftsche Ungleichung und er ist zudem auch präfixfrei. Betrachten wir nun die vorgeschlagenen neuen Codes.
 
  
:* Code T4 (<i>N</i><sub>1</sub> = 2, <i>N</i><sub>2</sub> = 2, <i>N</i><sub>3</sub> = 5):
+
'''(6)'''&nbsp; For code&nbsp; $\rm T3$&nbsp; it holds:  
:$$S({\rm T4})= S({\rm T3}) + 4 \cdot 3^{-3 } = {29}/{27}\hspace{0.1cm} > \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T4 \hspace{0.15cm}ist\hspace{0.15cm} ungeeignet}\hspace{0.05cm},$$
+
*$S({\rm T3})= 2 \cdot 3^{-1} + &nbsp;2 \cdot 3^{-2} + 1 \cdot 3^{-3 } = {25}/{27}\hspace{0.05cm}.$
 +
*Because of&nbsp; $S({\rm T3}) \le 1$&nbsp; the ternary code&nbsp; $\rm T3$&nbsp; satisfies Kraft's inequality and it is also prefix-free.
  
:* Code T5 (<i>N</i><sub>1</sub> = 2, <i>N</i><sub>2</sub> = 2, <i>N</i><sub>3</sub> = 1, <i>N</i><sub>4</sub> = 4):
 
:$$S({\rm T5})= S({\rm T3}) + 4 \cdot 3^{-4 } = {79}/{81}\hspace{0.1cm} < \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T5 \hspace{0.15cm}ist\hspace{0.15cm} geeignet}\hspace{0.05cm},$$
 
  
:* Code T6 (<i>N</i><sub>1</sub> = 2, <i>N</i><sub>2</sub> = 2, <i>N</i><sub>3</sub> = 2, <i>N</i><sub>4</Sub> = 3):
+
Let us now consider the proposed new codes.
:$$S({\rm T6})= S({\rm T3}) + 1 \cdot 3^{-3 } + 3 \cdot 3^{-4 } = \frac{75 + 3 + 3}{81}\hspace{0.1cm} = \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T6 \hspace{0.15cm}ist\hspace{0.15cm} geeignet}\hspace{0.05cm}.$$
+
* Code $\rm T4$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 5)$:
 +
:$$S({\rm T4})= S({\rm T3}) + 4 \cdot 3^{-3 } = {29}/{27}\hspace{0.1cm} > \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T4 \hspace{0.15cm}is\hspace{0.15cm} unsuitable}\hspace{0.05cm},$$
 +
* Code $\rm T5$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 1, \ N_4 = 4)$:
 +
:$$S({\rm T5})= S({\rm T3}) + 4 \cdot 3^{-4 } = {79}/{81}\hspace{0.1cm} < \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T5 \hspace{0.15cm}is\hspace{0.15cm} suitable}\hspace{0.05cm},$$
 +
* Code $\rm T6$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 2, \ N_4 = 3)$:
 +
:$$S({\rm T6})= S({\rm T3}) + 1 \cdot 3^{-3 } + 3 \cdot 3^{-4 } = \frac{75 + 3 + 3}{81}\hspace{0.1cm} = \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T6 \hspace{0.15cm}is\hspace{0.15cm} suitable}\hspace{0.05cm}.$$
  
:Richtig sind also die <u>zwei letzten</u> Lösungsvorschläge. Beispielsweise lauten die insgesamt 9 Codeworte des präfixfreien Codes T6: <b>0</b>, <b>1</b>, <b>20</b>, <b>21</b>, <b>220</b>, <b>221</b>, <b>2220</b>, <b>2221</b> und <b>2222</b>.
+
Thus, <u>the two last proposed solutions</u> are correct.
 +
 +
For example, the total&nbsp; $N = 9$&nbsp; code words of the prefix-free code&nbsp; $\rm T6$&nbsp;  are:
 +
:$$\rm 0, \, 1, \, 20, \,21, \,220, \,221, \,2220, \, 2221 , \,2222.$$
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Aufgaben zu Informationstheorie|^2.1 Allgemeine Beschreibung^]]
+
[[Category:Information Theory: Exercises|^2.1 General Description^]]

Latest revision as of 15:52, 1 November 2022

Four examples of binary codes and three ternary codes

In the figure some exemplary binary and ternary codes are given.

  • With the binary code  $\rm B1$  all possible source symbols  $q_\mu$  $($with index  $\mu = 1$, ... , $8)$  are represented by a encoded sequence  $\langle c_\mu \rangle $  of uniform length  $L_\mu = 3$ .
  • This code is unsuitable for data compression for this reason.


The possibility of data compression arises only when

  • the  $M$  source symbols are not equally likely, and
  • the length  $L_\mu$  of the code words are different.


For example, the binary code  $\rm B2$  has this property:  

  • Here, one code word each has the length   $1$,  $2$  and  $3$, respectively  $(N_1 = 1,\ N_2 = 2,\ N_3 = 3)$.
  • Two code words have the length  $L_\mu = 4$  $(N_4 = N_5 = 4)$.


A prerequisite for the decodability of such a code is that the code is  prefix-free . 

  • That is, no code word may be the prefix (i.e., the beginning) of a longer code word.
  • A necessary condition for a code for data compression to be prefix-free was stated by Leon Kraft in 1949, called  Kraft's inequality:
$$\sum_{\mu=1}^{M} \hspace{0.2cm} D^{-L_{\mu}} \le 1 \hspace{0.05cm}.$$

Here denote

  • $M$  the number of possible source symbols  $q_\mu$   ⇒   "symbol set size",
  • $L_\mu$  the length of the code word  $c_\mu$  associated with the source symbol  $q_\mu$,
  • $D = 2$  denotes a binary code  $(\rm 0$  or  $\rm 1)$  and  $D = 3$  denotes a ternary code  $(\rm 0$,  $\rm 1$,  $\rm 2)$.


A code can be prefix-free only if Kraft's inequality is satisfied. 

The converse does not hold:   If Kraft's inequality is satisfied, it does not mean that this code is actually prefix-free.



Hint:


Question

1

Which of the binary codes satisfy Kraft's inequality?

$\rm B1$,
$\rm B2$,
$\rm B3$,
$\rm B4$.

2

Which of the given binary codes are prefix-free?

$\rm B1$,
$\rm B2$,
$\rm B3$,
$\rm B4$.

3

Which of the given ternary codes are prefix-free?

$\rm T1$,
$\rm T2$,
$\rm T3$.

4

What are the characteristics of the ternary code  $\rm T1$?

$ N_1 \ = \ $

$ N_2 \ = \ $

$ N_3 \ = \ $

5

How many trivalent code words  $(L_\mu = 3)$  could be added to the  $\rm T1$  code without changing the prefix freedom?

$\Delta N_3 \ = \ $

6

The ternary code  $\rm T3$  is to be expanded to a total of  $N = 9$  code words.  How to achieve this without violating the prefix freedom?

Addition of four three-valued code words.
Addition of four four-valued code words.
Addition of one trivalent and three tetravalent code words.


Solution

(1)  The correct solutions are 1, 2 and 3.  The following applies to the binary codes given:

  • $\rm B1$:    $8 \cdot 2^{-3} = 1$   ⇒   condition fulfilled,
  • $\rm B2$:    $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 1 \cdot 2^{-3} + 2 \cdot 2^{-4}= 1$   ⇒   condition fulfilled,
  • $\rm B3$:    $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 1 \cdot 2^{-3} + 2 \cdot 2^{-4}= 1$   ⇒   condition fulfilled,
  • $\rm B4$:    $1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 2 \cdot 2^{-3} + 1 \cdot 2^{-4}= 17/16$   ⇒   condition not fulfilled.


(2)  Proposed solutions 1 and 2 are correct:

  • The code  $\rm B4$, which does not satisfy Kraft's inequality, is certainly not prefix-free either.
  • But if Kraft's inequality is fulfilled, it is still not certain that this code is also prefix-free.
  • In code  $\rm B3$  the code word  "10"  is the beginning of the code word  "1011".
  • In contrast, codes  $\rm B1$  and  $\rm B2$  are actually prefix-free.


(3)  The correct solutions are 1 and 3:

  • Kraft's inequality is satisfied by all three codes.
  • As can be seen from the table, codes  $\rm T1$  and  $\rm T3$  are indeed prefix-free.
  • The code  $\rm T2$ , on the other hand, is not prefix-free because "1" is the beginning of the code word "10".


(4)  $N_i$  indicates how many code words with  $i$  symbols there are in the code.  For the code  $\rm T1$  it is:

$$N_1 \hspace{0.15cm}\underline{= 1}\hspace{0.05cm}, \hspace{0.2cm}N_2 \hspace{0.15cm}\underline{= 2}\hspace{0.05cm}, \hspace{0.2cm}N_3 \hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$


(5)  According to Kraft's inequality, the following must be true

$$N_1 \cdot 3^{-1} + N_2 \cdot 3^{-2} + N_3 \cdot 3^{-3 } \le 1\hspace{0.05cm}.$$

For given  $N_1 = 1$  and  $N_2 = 2$  , this is satisfied as long as holds:

$$N_3 \cdot 3^{-3 } \le 1 - 1/3 - 2/9 = 4/9 \hspace{0.3cm} \Rightarrow \hspace{0.3cm}N_3 \le 12 \hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm \Delta}\,N_3 \hspace{0.15cm}\underline{= 6}\hspace{0.05cm}.$$

The additional code words are  $\rm 210, \,211, \,212, \,220, \,221, \,222$.


(6)  For code  $\rm T3$  it holds:

  • $S({\rm T3})= 2 \cdot 3^{-1} +  2 \cdot 3^{-2} + 1 \cdot 3^{-3 } = {25}/{27}\hspace{0.05cm}.$
  • Because of  $S({\rm T3}) \le 1$  the ternary code  $\rm T3$  satisfies Kraft's inequality and it is also prefix-free.


Let us now consider the proposed new codes.

  • Code $\rm T4$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 5)$:
$$S({\rm T4})= S({\rm T3}) + 4 \cdot 3^{-3 } = {29}/{27}\hspace{0.1cm} > \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T4 \hspace{0.15cm}is\hspace{0.15cm} unsuitable}\hspace{0.05cm},$$
  • Code $\rm T5$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 1, \ N_4 = 4)$:
$$S({\rm T5})= S({\rm T3}) + 4 \cdot 3^{-4 } = {79}/{81}\hspace{0.1cm} < \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T5 \hspace{0.15cm}is\hspace{0.15cm} suitable}\hspace{0.05cm},$$
  • Code $\rm T6$ $(N_1 = 2, \ N_2 = 2, \ N_3 = 2, \ N_4 = 3)$:
$$S({\rm T6})= S({\rm T3}) + 1 \cdot 3^{-3 } + 3 \cdot 3^{-4 } = \frac{75 + 3 + 3}{81}\hspace{0.1cm} = \hspace{0.1cm}1\hspace{0.3cm} \Rightarrow \hspace{0.3cm} {\rm T6 \hspace{0.15cm}is\hspace{0.15cm} suitable}\hspace{0.05cm}.$$

Thus, the two last proposed solutions are correct.

For example, the total  $N = 9$  code words of the prefix-free code  $\rm T6$  are:

$$\rm 0, \, 1, \, 20, \,21, \,220, \,221, \,2220, \, 2221 , \,2222.$$