t00340020120134069t0034-pert 19-huffman code

Upload: richmafia21

Post on 23-Feb-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    1/14

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    2/14

    Session 19Huffman Code

    Course : T0034 Algorithm Design & Analysis

    ear : !013

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    3/14

    Bina Nusantara

    DATA COMPRESSION

    " Ho# does a $om%ression %rogram really #or'

    " (hy $an si)e of file *e redu$ed #ithout redu$ing its$ontain'

    " Su%%osed #e #ill store letter A+ Com%uter re$ogni)es theletter as a $hara$ter #ith se,uen$e -./ then the letter isstored in harddis as 1000001 *inary num*er of -.

    de$imal+ 2t needs *inary digit to store letter A+

    " Data $om%ression tries to store as minimum as %ossi*lenum*er of *inary digits+

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    4/14

    Bina Nusantara

    ENCODING CHARACTER

    " ASCIIAmerican Standard Code for Information Interchange ASC22 $hara$ter en$oding $onsists 1! $hara$ters5 *it *inary num*ers5

    %rinted 9. $hara$ters and 33 $ommand $hara$ter+

    " ISO 8859-1is a standard $hara$ter #ith *it/ $an store !.- $hara$ters+

    This standar is $alled as character encodingLatin-1+" UTF-8Unicode Transformation Format is a standard encoding

    character that ena*le many languages as sho#n in the same time+6um*er of *it to store a $hara$ter is different+ ASC22 $hara$ter is stored in 1 *yte *it+

    7atin/ 8ree/ Cyrilli$/ Armenian/ He*re#/ Ara*i$/ Syria$ dan Thaana$hara$ter is stored in ! *yte 1- *it+

    ther laguages $hara$ter is stored in 3 *yte !4 *it+ Chara$ter of a#a;

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    5/14

    Bina Nusantara

    CHARACTER TABLE

    Binary # C Binary # C Binary # C0010 0000 3! s% 0100 0000 -4 > 0110 0000 9- ?

    0010 0001 33 @ 0100 0001 -. A 0110 0001 9 a

    0010 0010 34 0100 0010 -- < 0110 0010 9 *

    0010 0011 3. B 0100 0011 - C 0110 0011 99 $

    0010 0100 3- 0100 0100 - D 0110 0100 100 d

    0010 0101 3 0100 0101 -9 E 0110 0101 101 e

    0010 0110 3 & 0100 0110 0 F 0110 0110 10! f

    0010 0111 39 G 0100 0111 1 8 0110 0111 103 g

    0010 1000 40 0100 1000 ! H 0110 1000 104 h

    0010 1001 41 0100 1001 3 2 0110 1001 10. i0010 1010 4! 0100 1010 4 0110 1010 10- I

    0010 1011 43 J 0100 1011 . K 0110 1011 10

    0010 1100 44 / 0100 1100 - 7 0110 1100 10 l

    0010 1101 4. L 0100 1101 M 0110 1101 109 m

    0010 1110 4- + 0100 1110 6 0110 1110 110 n

    0010 1111 4 ; 0100 1111 9 0110 1111 111 o

    0011 0000 4 0 0101 0000 0 N 0111 0000 11! %

    0011 0001 49 1 0101 0001 1 O 0111 0001 113 ,

    0011 0010 .0 ! 0101 0010 ! P 0111 0010 114 r

    0011 0011 .1 3 0101 0011 3 S 0111 0011 11. s

    0011 0100 .! 4 0101 0100 4 T 0111 0100 11- t

    0011 0101 .3 . 0101 0101 . Q 0111 0101 11 u

    0011 0110 .4 - 0101 0110 - R 0111 0110 11

    0011 0111 .. 0101 0111 ( 0111 0111 119 #

    0011 1000 .- 0101 1000 0111 1000 1!0 =

    0011 1001 . 9 0101 1001 9 0111 1001 1!1 y

    0011 1010 . : 0101 1010 90 U 0111 1010 1!! )

    0011 1011 .9 5 0101 1011 91 V 0111 1011 1!3 W

    0011 1100 -0 X 0101 1100 9! Y 0111 1100 1!4 Z

    0011 1101 -1 [ 0101 1101 93 \ 0111 1101 1!. ]

    0011 1110 -! ^ 0101 1110 94 _ 0111 1110 1!- `

    0011 1111 -3 ' 0101 1111 9.

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    6/14

    Bina Nusantara

    HUFFMAN ALGORITHM

    " 2nented *y Daid A+ Huffman in 19.1 #hen hestudied his Nh+D at Massa$husetts 2nstitute ofTe$hnology M2T+

    " He dis$oered a method to *uild *inary tree *asedon fre,uen$y+ The

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    7/14Bina Nusantara

    CREATING A HUFFMAN TREE

    " Sort $hara$ters from the smalest fre,uen$y in a ta*le+

    " Choose to% ! $hara$ters/ mae as leaf node of the tree+6ode the $hara$ter and its fre,uen$y+

    " Mae ne# node as %arent of the t#o leaf nodes+ 2tsfe,uen$y $omes from *oth $hildrent+

    " Pemoe used nodes from the ta*le+

    " Enter ne# node to the ta*le+

    " Pe%eat ste% ! until all nodes remoed+

    "

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    8/14Bina Nusantara

    EXAMPLE CASE

    " Su%%osed #e store #ords: 782KA A78P2TMA

    " Then/ fre,uen$y ta*le is:

    K R T M sp L O G I A

    1 1 1 1 1 ! ! ! ! 3

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    9/14Bina Nusantara

    HUFFMAN TREE

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    10/14Bina Nusantara

    HUFFMAN CODE TABLE

    " 7 011 3 *it

    " 100 3 *it" 8 101 3 *it" 2 110 3 *it" K 11110 . *it" A 00 ! *it" s% 1110 4 *it" A 00 ! *it" 7 011 3 *it

    " 8 101 3 *it" 100 3 *it" P 11111 . *it" 2 110 3 *it" T 0100 4 *it" M 0101 4 *it" A 00 ! *it

    K R T M sp L O G I A

    11110 11111 0100 0101 1110 011 100 101 110 00

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    11/14Bina Nusantara

    EXERCISE

    " Create fre,uen$y ta*le/ Huffman Tree/ andHuffman Code to $om%ress:

    DES286 A6D A6A7S2S F A78P2THMS

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    12/14Bina Nusantara

    REVIEW

    " DATA CMNPESS26

    " E6CD268 CHAPACTEP

    " CHAPACTEP TA

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    13/14Bina Nusantara

    Books References

    " Peferen$es: Com%uter Algorithms ; CJJ

    " Ellis Horo#it)/ SartaI Sahni/ Sanguthear PaIasearan+

    " Com%uter S$ien$e Nress+ 199

    2ntrodu$tion to Algorithms" Thomas H Cormen/ Charles E 7eiserson/ Ponald 7+

    " 3ndEdition+ The M2T Nress+ 6e# or+ !009

    Algoritma 2tu Mudah" Po*ert Setiadi+

    " NT Nrima 2nfosarana Media/ Kelom%o 8ramedia+

    " aarta+ !00

  • 7/24/2019 T00340020120134069T0034-Pert 19-Huffman Code

    14/14Bina Nusantara

    END