Hu man codes - .Hu man codes St‹jhcZ‹qoc ......

download Hu man codes - .Hu man codes St‹jhcZ‹qoc ... e—nai adrfiastokatâ€tatoep—pedo. Hap¬deixhtoul€mmatoc

of 33

  • date post

    29-Jul-2018
  • Category

    Documents

  • view

    214
  • download

    0

Embed Size (px)

Transcript of Hu man codes - .Hu man codes St‹jhcZ‹qoc ......

  • Huffman codes

    8 2014

  • 1

    2 Huffman

  • 1

    2 Huffman

  • . (.. ASCII), Huffman () . .. a, e, h, i, n, o,s, t, space j, k, q, v, x,z. a, b, c, d, e, f, g : 0.25, 0.21, 0.18, 0.14, 0.09, 0.07, 0.06, : 01, 11, 000,001, 101, 1000, 1001 :

    . () Huffman codes 8 2014 4 / 21

  • Huffman : n . .

    . () Huffman codes 8 2014 5 / 21

  • : :

    : S - : O

    : c - : c , |c | = c

    c S : fS(c)

    . () Huffman codes 8 2014 6 / 21

  • O = C (S)

    S , .

    : = {a, b, c , d}:

    C (a) = 0,C (b) = 110,C (c) = 10,C (d) = 111

    C (bad) = 1100111

    . () Huffman codes 8 2014 7 / 21

  • S = D(O)

    O, .

    D(00) = a,D(01) = b,D(10) = c ,D(11) = d

    D(010011) = bad

    . () Huffman codes 8 2014 8 / 21

  • 1-1, , . C ,D c : c = D(C (c))

    . () Huffman codes 8 2014 9 / 21

  • : Prefix Code

    Prefix Code prefix .

    : C (a, b, c , d) = (0, 110, 10, 111) Prefix Code

    :

    Prefix Code .

    . () Huffman codes 8 2014 10 / 21

  • S ( ). , :

    S = {c1, . . . , cn}, C ,

    B(C ) =n

    i=1

    fS(ci) |C (ci)|

    . () Huffman codes 8 2014 11 / 21

  • prefix code T .

    : 0 - : 1

    c c

    B(C ) =n

    i=1

    fS(ci) |C (ci)| =n

    i=1

    fS(ci) depth(ci) = B(T )

    . () Huffman codes 8 2014 12 / 21

  • Huffman

    Huffman

    Huffman, (MIT), Prefix Code. 1952.

    . () Huffman codes 8 2014 13 / 21

  • Huffman

    PROC huffman(int n);{int i ;FOR (i , 1 TO n 1){ Merge last two subtrees; Rearrange subtrees in nondecreasing order of root - probability;}}

    : O(n log n) ( heap)

    . () Huffman codes 8 2014 14 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    . () Huffman codes 8 2014 15 / 21

  • Huffman

    Pazcal Huffman. , ( ):

    Pazcal ( ) .

    . () Huffman codes 8 2014 16 / 21

  • Huffman

    1

    prefix code , .

    .

    . .

    . () Huffman codes 8 2014 17 / 21

  • Huffman

    1

    prefix code , .

    .

    . .

    . () Huffman codes 8 2014 17 / 21

  • Huffman

    2

    x y , .

    .

    . () Huffman codes 8 2014 18 / 21

  • Huffman

    2

    x y , .

    .

    . () Huffman codes 8 2014 18 / 21

  • Huffman

    .

    T b c . T . f (b) f (c) f (x) f (y).

    x , y f (x) f (b) f (y) f (c), b c depth(b) depth(x) depth(c) depth(y). x b T . B(T ) B(T ) =B(T )f (x)depth(x)f (b)depth(b)+f (x)depth(b)+f (b)depth(x) =B(T ) + (f (x) f (b))(depth(b) depth(x)) B(T ) B(T ) = B(T ), T . y c T .

    . () Huffman codes 8 2014 19 / 21

  • Huffman

    .

    T b c . T . f (b) f (c) f (x) f (y). x , y f (x) f (b) f (y) f (c), b c depth(b) depth(x) depth(c) depth(y). x b T .

    B(T ) B(T ) =B(T )f (x)depth(x)f (b)depth(b)+f (x)depth(b)+f (b)depth(x) =B(T ) + (f (x) f (b))(depth(b) depth(x)) B(T ) B(T ) = B(T ), T . y c T .

    . () Huffman codes 8 2014 19 / 21

  • Huffman

    .

    T b c . T . f (b) f (c) f (x) f (y). x , y f (x) f (b) f (y) f (c), b c depth(b) depth(x) depth(c) depth(y). x b T . B(T ) B(T ) =B(T )f (x)depth(x)f (b)depth(b)+f (x)depth(b)+f (b)depth(x) =B(T ) + (f (x) f (b))(depth(b) depth(x)) B(T ) B(T ) = B(T ), T .

    y c T .

    . () Huffman codes 8 2014 19 / 21

  • Huffman

    .

    T b c . T . f (b) f (c) f (x) f (y). x , y f (x) f (b) f (y) f (c), b c depth(b) depth(x) depth(c) depth(y). x b T . B(T ) B(T ) =B(T )f (x)depth(x)f (b)depth(b)+f (x)depth(b)+f (b)depth(x) =B(T ) + (f (x) f (b))(depth(b) depth(x)) B(T ) B(T ) = B(T ), T . y c T .

    . () Huffman codes 8 2014 19 / 21

  • Huffman

    3

    T . x y T , z . z . x y z f (z) = f (x) + f (y), z ( x y) .

    ... .

    . () Huffman codes 8 2014 20 / 21

  • Huffman

    3

    T . x y T , z . z . x y z f (z) = f (x) + f (y), z ( x y) .

    ... .

    . () Huffman codes 8 2014 20 / 21

  • Huffman

    ...

    ( 7 )

    . () Huffman codes 8 2014 21 / 21

    Huffman