Struktur Data & Algoritme ( Data Structures & Algorithms ) - - PDF document

struktur data algoritme data structures algorithms
SMART_READER_LITE
LIVE PREVIEW

Struktur Data & Algoritme ( Data Structures & Algorithms ) - - PDF document

Struktur Data & Algoritme ( Data Structures & Algorithms ) Tree: application Denny ( denny@cs.ui.ac.id ) Suryana Setiawan ( setiawan@cs.ui.ac.id ) Fakultas I lm u Kom puter Universitas I ndonesia Sem ester Genap - 2 0 0 4 / 2 0 0 5


slide-1
SLIDE 1

1

Struktur Data & Algoritme ( Data Structures & Algorithms)

Denny (denny@cs.ui.ac.id) Suryana Setiawan (setiawan@cs.ui.ac.id)

Fakultas I lm u Kom puter Universitas I ndonesia Sem ester Genap - 2 0 0 4 / 2 0 0 5

Version 2 .0 - I nternal Use Only

Tree: application

SDA/ HUFF/ V2.0/ 2

Objectives

understand one of file compression technique

(Huffman)

slide-2
SLIDE 2

2

SDA/ HUFF/ V2.0/ 3

Outline

Compression Huffman compression

SDA/ HUFF/ V2.0/ 4

Compression

Process: Encoding: raw → compressed Decoding: compressed → raw Types of compression Lossy : MPEG, JPEG Lossless Compression Algorithm: RLE: Run Length Encoding Lempel-Zif Huffman Encoding Performance of compression depends on file types.

slide-3
SLIDE 3

3

SDA/ HUFF/ V2.0/ 5

Huffman Compression

If a woodchuck could chuck wood! 32 char × 8 bit = 256 bits 13 distinct characters → 4 bit Compressed code: 128 bits Variable length string of bits to further improve

compression.

Using prefix codes

SDA/ HUFF/ V2.0/ 6

Huffman Compression

Frequently occurring letters: short representation. Infrequent letters: long representations.

slide-4
SLIDE 4

4

SDA/ HUFF/ V2.0/ 7

i a u e

8 5 3 3

Huffman Encoding: comparation

a = 00 → 16 bits i = 01 → 10 bits u = 10 → 6 bits e = 11 → 6 bits Total : 4 2 bits

SDA/ HUFF/ V2.0/ 8

Huffman Encoding: comparation

i 5 a

8

u

3

e

3 6 11 19 a = 0 → 8 bits i = 10 → 10 bits u = 110 → 9 bits e = 111 → 9 bits Total: 3 6 bits

slide-5
SLIDE 5

5

SDA/ HUFF/ V2.0/ 9

1 1 1 1 1 1 1 1 1 1 1 1 ! a l u d k w I f h c

  • space

Huffman Encoding

SDA/ HUFF/ V2.0/ 10

13 6 3 4 9 2 32 19 10 7 4 2 !:1 a:1 l:1 u:3 d:3 k:2 w :2 I :1 f:1 h:2 c:5

  • :5

space:5

Huffman Encoding

slide-6
SLIDE 6

6

SDA/ HUFF/ V2.0/ 11

Huffman Encoding (freq)

! = 0 0 0 0 ( 1 ) I = 1 0 0 0 0 ( 1 ) a = 0 0 0 1 0 ( 1 ) f = 1 0 0 0 1 ( 1 ) l = 0 0 0 1 1 ( 1 ) h = 1 0 0 1 ( 2 ) u = 0 0 1 ( 3 ) c = 1 0 1 ( 5 ) d = 0 1 0 ( 3 ) space= 1 1 0 ( 5 ) k = 0 1 1 0 ( 2 )

  • = 1 1 1 ( 5 )

w = 0 1 1 1 ( 2 ) Cost: ∑ di * fi = 1 1 1 bits = 4 4 % × 2 5 6 bits

SDA/ HUFF/ V2.0/ 12

Huffman Encoding: steps

c 5

  • 5

5

u

3

d

3

w

2

k

2

a

1

l

1

f

1

I

1

h

2

!

1 2

slide-7
SLIDE 7

7

SDA/ HUFF/ V2.0/ 13

Huffman Encoding: steps

c 5

  • 5

5

u

3

d

3

w

2

k

2

f

1

I

1

h

2

!

1

a l

2 2

SDA/ HUFF/ V2.0/ 14

Huffman Encoding: steps

c 5

  • 5

5

u

3

d

3

w

2

k

2

I

1

h

2

a l

2

f !

2 3

slide-8
SLIDE 8

8

SDA/ HUFF/ V2.0/ 15

c 5

  • 5

5

u

3

d

3

w

2

k

2

h

2

a l

2

I f !

3 4

Huffman Encoding: steps

SDA/ HUFF/ V2.0/ 16

c 5

  • 5

5

u

3

d

3

k

2

a l

2

I f !

3 4

w h

4

Huffman Encoding: steps

slide-9
SLIDE 9

9

SDA/ HUFF/ V2.0/ 17

Huffman Encoding: steps

c 5

  • 5

5

u

3

d

3

I f !

3 4

w h k a l

4 6

SDA/ HUFF/ V2.0/ 18

Huffman Encoding: steps

c 5

  • 5

5

f !

3 4

w h k a l

4

u d

6

I

slide-10
SLIDE 10

10

SDA/ HUFF/ V2.0/ 19

c 5

  • 5

5

f !

3 4

w h k a l

4

u d

6

I

7

Huffman Encoding: steps

SDA/ HUFF/ V2.0/ 20

Huffman Encoding: steps

c 5

  • 5

5 4

w h u d

6

f ! k a l I

7 9

slide-11
SLIDE 11

11

SDA/ HUFF/ V2.0/ 21

  • 5

5

u d

6

f ! k a l I

7

c w h

9 10

Huffman Encoding: steps

SDA/ HUFF/ V2.0/ 22

u d

6

f ! k a l I

7

c w h

9

  • 10

13

Huffman Encoding: steps

slide-12
SLIDE 12

12

SDA/ HUFF/ V2.0/ 23

c w h

9

  • 10

u d f ! k a l I

13 19

Huffman Encoding: steps

SDA/ HUFF/ V2.0/ 24

u d f ! k a l I

13

c w h

  • 19

32

Huffman Encoding: steps

slide-13
SLIDE 13

13

SDA/ HUFF/ V2.0/ 25

Huffman Encoding: steps

u d f ! k a l I c w h

  • Total: 111 bits

SDA/ HUFF/ V2.0/ 26

Summary

Huffman encoding use frequency information to

compress file.

The most frequent character get a shorter prefix

code, and vice versa.

slide-14
SLIDE 14

14

SDA/ HUFF/ V2.0/ 27

Further Reading

Chapter 12

SDA/ HUFF/ V2.0/ 28

What’s Next

Hash Tables