3/25/13 CS200 Algorithms and Data Structures Colorado State - - PDF document

3 25 13
SMART_READER_LITE
LIVE PREVIEW

3/25/13 CS200 Algorithms and Data Structures Colorado State - - PDF document

3/25/13 CS200 Algorithms and Data Structures Colorado State University CS200 Algorithms and Data Structures Colorado State University PA3: Com ompres essing Data using Huffm Hu ffman Cod oding Sangmi Pallickara 3/25/13 2 Samgmi


slide-1
SLIDE 1

3/25/13 ¡ 1 ¡

CS200 Algorithms and Data Structures Colorado State University

PA3: Com

  • mpres

essing Data using Hu Huffm ffman Cod

  • ding

Sangmi Pallickara

CS200 Algorithms and Data Structures Colorado State University 3/25/13 Samgmi Lee Pallickara 2 CS200 Algorithms and Data Structures Colorado State University

Com

  • mpres

essing Data using Hu Huffm ffman Cod

  • ding
  • Take String input
  • Generate compressed bits

CS200 Algorithms and Data Structures Colorado State University

Hu Huffm ffman cod

  • ding?
  • Uses the symbols and their frequencies
  • Constructs rooted binary tree

– Symbols are stored in the leaves

  • Example:
  • AEMMMEEKKMAABBBEEEEGGGMMMGGK

MGKKKKKMMMMAKKKKMEGGGKKKKKKBB EEEEMGGGMMMABBMMABBBMMMMGGGM MMMMMMKKKMMMAAMM

CS200 Algorithms and Data Structures Colorado State University

Crea eate e a Fr Freq equen ency table e

Character ¡ Frequency ¡ Huffman ¡code ¡

A ¡ 8 ¡ B ¡ 10 ¡ E ¡ 12 ¡ G ¡ 15 ¡ K ¡ 20 ¡ M ¡ 35 ¡

CS200 Algorithms and Data Structures Colorado State University

Start fr from

  • m a For

Fores est of

  • f Trees

ees

slide-2
SLIDE 2

3/25/13 ¡ 2 ¡

CS200 Algorithms and Data Structures Colorado State University CS200 Algorithms and Data Structures Colorado State University

Gen ener erate e Hu Huffm ffman cod

  • de

e

Character ¡ Frequency ¡ Huffman ¡code ¡

A ¡ 8 ¡ 111 ¡ B ¡ 10 ¡ 110 ¡ E ¡ 12 ¡ 011 ¡ G ¡ 15 ¡ 010 ¡ K ¡ 20 ¡ 10 ¡ M ¡ 35 ¡ 00 ¡

CS200 Algorithms and Data Structures Colorado State University

Now

  • w, en

encod

  • de

e you

  • ur string
  • AEMMMEEKKMAABBBEEEEGGGMMMGGK

MGKKKKKMMMMAKKKKMEGGGKKKKKKBB EEEEMGGGMMMABBMMABBBMMMMGGGM MMMMMMKKKMMMAAMM 

  • 111(A)
  • 011(E)
  • 00(M)

CS200 Algorithms and Data Structures Colorado State University

Dec ecod

  • de

e the e string

  • If your encoded bit is 11100011 and you have

the Huffman Tree,

CS200 Algorithms and Data Structures Colorado State University

Exer ercise e

  • Build a Huffman Frequency Table for,

“Colorado” Assume that each of the symbols are Java char (16-bit unicode character)

3/25/13 Samgmi Lee Pallickara 11 CS200 Algorithms and Data Structures Colorado State University

Build a Hu Huffm ffman Tree ee based ed on

  • n the

e table e

3/25/13 Samgmi Lee Pallickara 12

slide-3
SLIDE 3

3/25/13 ¡ 3 ¡

CS200 Algorithms and Data Structures Colorado State University

Encod

  • de

e the e String

3/25/13 Samgmi Lee Pallickara 13 CS200 Algorithms and Data Structures Colorado State University

Dec ecod

  • de

e it

3/25/13 Samgmi Lee Pallickara 14 CS200 Algorithms and Data Structures Colorado State University

You

  • ur tes

est ou

  • utput will look
  • ok like,

e,

% java PA3_Test eeyjjjj ====================================== char frequency code

  • e 2 10

y 1 11 j 4 0 ====================================== Encoded bit stream 1010110000 Total number of bits without Huffman coding: 112 Total number of bits with Huffman coding: 10 Decoded String: eeyjjjj

CS200 Algorithms and Data Structures Colorado State University

  • Write the implementer’s name(s) on top of each
  • f the source code
  • Work with the same partner (unless you get an

email after this class)