15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 210 The Morse Code in the table above induces a character code µ: R → {., −}.<br />

Codes on Strings<br />

c○: Michael Kohlhase 121<br />

Definition 211 A function c ′ : A ∗ → B ∗ is called a code on strings or short string code if<br />

c ′ is an injective function.<br />

Theorem 212 ( ) There are character codes whose extensions are not string codes.<br />

Proof: we give an example<br />

P.1 Let A = {a, b, c}, B = {0, 1}, c(a) = 0, c(b) = 1, and c(c) = 01.<br />

P.2 The function c is injective, hence it is a character code.<br />

P.3 But its extension c ′ is not injective as c ′ (ab) = 01 = c ′ (c).<br />

Question: When is the extension of a character code a string code?(so we can encode strings)<br />

Definition 213 A (character) code c: A → B + is a prefix code iff none of the codewords<br />

is a proper prefix to an other codeword, i.e.,<br />

∀x, y ∈ A.x = y ⇒ (c(x) ⊳ c(y) ∧ c(y) ⊳ c(x))<br />

c○: Michael Kohlhase 122<br />

We will answer the question above by proving one of the central results of elementary coding<br />

theory: prefix codes induce string codes. This plays back the infinite task of checking that a string<br />

code is injective to a finite task (checking whether a character code is a prefix code).<br />

Prefix Codes induce Codes on Strings<br />

Theorem 214 The extension c ′ : A ∗ → B ∗ of a prefix code c: A → B + is a string code.<br />

Proof: We will prove this theorem via induction over the string length n<br />

P.1 We show that c ′ is injective (decodable) on strings of length n ∈ N.<br />

P.1.1 n = 0 (base case):<br />

If |s| = 0 then c ′ (ɛ) = ɛ, hence c ′ is injective.<br />

P.1.2 n = 1 (another):<br />

If |s| = 1 then c ′ = c thus injective, as c is char. code.<br />

P.1.3 Induction step (n to n + 1):<br />

P.1.3.1 Let a = a0, . . ., an, And we only know c ′ (a) = c(a0), . . ., c(an).<br />

P.1.3.2 It is easy to find c(a0) in c ′ (a): It is the prefix of c ′ (a) that is in c(A). This is uniquely<br />

determined, since c is a prefix code. If there were two distinct ones, one would have to be a<br />

prefix of the other, which contradicts our assumption that c is a prefix code.<br />

P.1.3.3 If we remove c(a0) from c(a), we only have to decode c(a1), . . ., c(an), which we can do by<br />

inductive hypothesis.<br />

P.2 Thus we have considered all the cases, and proven the assertion.<br />

c○: Michael Kohlhase 123<br />

66

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!