Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Huffman Codes: Data Structures and Algorithms Project 2 - Prof. David J. Galles, Study Guides, Projects, Research of Data Structures and Algorithms

Instructions for project 2 of the cs245-2009s data structures and algorithms course at the university of san francisco. The project focuses on huffman codes, a method for compressing data by assigning variable-length codes to characters based on their frequency. Topics such as ascii codes, representing codes as trees, prefix codes, variable length codes, file length, decoding files, file compression, and huffman coding. Students are expected to use this information to complete the project.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 07/30/2009

koofers-user-i8y-1
koofers-user-i8y-1 🇺🇸

10 documents

1 / 56

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures and Algorithms
CS245-2009S-P2
Huffman Codes
Project 2
David Galles
Department of Computer Science
University of San Francisco
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38

Partial preview of the text

Download Huffman Codes: Data Structures and Algorithms Project 2 - Prof. David J. Galles and more Study Guides, Projects, Research Data Structures and Algorithms in PDF only on Docsity!

Data Structures and Algorithms

CS245-2009S-P2Huffman Codes

Project 2^ David Galles

Department of Computer Science

University of San Francisco

Text Files All files are represented as binary digits – includingtext files Each character is represented by an integer code

ASCII – American Standard Code forInformation Interchange Text file is a sequence of binary digits whichrepresent the codes for each character.

ASCII Each character in ASCII is represented as 8 bits

We need 8 bits to represent all possiblecharacter combinations

(including control characters, and unprintablecharacters) Breaking up file into individual characters iseasy Finding the kth character in a file is easy

ASCII ASCII is not terribly efficient

All characters require 8 bits Frequently used characters require the samenumber of bits as infrequently used characters We could be more efficient if frequently usedcharacters required fewer than 8 bits, and lessfrequently used characters required more bits

Representing Codes as Trees Want to encode 4 only characters: a, b, c, d(instead of 256 characters)

How many bits are required for each code, ifeach code has the same length? 2 bits are required, since there are 4 possibleoptions to distinguish

Representing Codes as Trees Want to encode 4 only characters: a, b, c, d Pick the following codes:

a: 00 b: 01 c: 10 d: 11 We can represent these codes as a tree

Characters are stored at the leaves of the tree Code is represented by path to leaf

Representing Codes as Trees a: 01, b: 00, c: 11, d:

a

b^

c

d

0

1

0

0

1

1

Prefix Codes If no code is a prefix of any other code, thendecoding the file is unambiguous. If all codes are the same length, then no code willbe a prefix of any other code (trivially) We can create variable length codes, where nocode is a prefix of any other code

Prefix Codes & Trees

Any prefix code can be represented as a tree a: 0, b: 100, c: 101, d: 11

c

d

0

1 0

(^01)

1

a

b

File Length

If we use the code:

a:00, b:01, c:10, d: How many bits are required to encode a file of 20characters?

File Length

If we use the code:

a:0, b:100, c:101, d: How many bits are required to encode a file of 20characters?

File Length

If we use the code:

a:0, b:100, c:101, d: How many bits are required to encode a file of 20characters? It depends upon the number of a’s, b’s, c’s and d’sin the file

File Length

If we use the code:

a:0, b:100, c:101, d: How many bits are required to encode a file of:

11 a’s, 2 b’s, 2 c’s, and 5 d’s? 111 + 23 + 23 + 52 = 33 < 40

Decoding Files

We can use variable length keys to encode a textfile Given the encoded file, and the tree representationof the codes, it is easy to decode the file

c

d

0

(^10)

(^01)

1

a

b 0111001010011