Data structures' project
COMSATS Institute of Information & Technology,
                     Islamabad
             Subject : Data Structures


                           A presentation
                                 by
                            Ayesha Arif
                          FA10-BSB-014
                                 &
                         Ghazanfar Ali Baig
                          FA10-BSB-024
    Instructor Name:
                       Ms. Nusrat Shaheen
Huffman’s Code
Background
• When we encode characters in computers, we assign
  each an 8-bit code based on an ASCII chart.
• But in most files, some characters appear more often
  than others.
• So wouldn't it make more sense to assign shorter
  codes for characters that appear more often and
  longer codes for characters that appear less often?
Data Compressions
• Lossless compressions:
Less space is used, or energy to transmit it.
–No information is lost –we can reconstruct
  the
original text
–Often: be able to quickly reconstruct original
  text
• Lossy compressions.
Data Compressions
• Text representation:
• ASCII: 1 byte per character (fixed length
  code)
  – “M          A         R         C”
  1st Byte 2nd Byte     3rd Byte 4th byte
  77       97           114      99
  01001101 01100001     01110010 01100011
• In the English language, the letter „e‟ is, „quite
  common x‟ is less common–Why should all
  characters be represented using the same
  number of bits?
Huffman

• 1951, David Huffman found
  the “most efficient method of
  representing numbers,
  letters, and other symbols
  using binary code”
• Now standard method used
  for data compression
The Concept

• Huffman coding has the following properties:

• Codes for more probable characters are shorter
  than ones for less probable characters.

• Each code can be uniquely decoded .
The Concept
• To read the codes from a Huffman tree, start from the
  root and add a '0' every time you go left to a child,
  and add a '1' every time you go right. So in this
  example, the code for the character 'b' is 01 and the
  code for 'd' is 110.
• As you can see, 'a' has a shorter code than 'd'. Notice
  that since all the characters are at the leafs of the tree
  (the ends), there is never a chance that one code will
  be the prefix of another one (eg. 'a' is 00 and 'b' is 011
• ).
• Hence, this unique prefix property assures that each
  code can be uniquely decoded.
Huffman Codes

• How to construct Huffman codes?
• Build a binary tree!
Binary Tree

• A binary tree is a tree where each internal node
  has at most 2 children.
Internal
                  The “Root Node”   A        Vertex


The “Left Node”           B                 C       The “Right Node”




                  D           E         F       G

                       Sibling
                       Nodes
                                                           Leaf
                                 Binary Tree              Vertex
Algorithm
1.Take the characters and their frequencies, and this list
   by increasing frequency.
2 .All the characters are vertices of the tree.
3.Take the first 2 vertices from the list and make them
   children of a vertex having the sum of their
   frequencies.
4.Insert the new vertex into the sorted list of vertices
   waiting to be put into the tree.
5.If there are at least 2 vertices in the list, go to
   step 3.
6.Read the Huffman code from the tree.
Huffman’s Code
1.Take the characters and their frequencies, and
  sort this list by increasing frequency



A: 3, O: 5, T: 7, E:10
Huffman’s Code

2. All the characters are the vertices of the tree:


      A:3          O:5          T:7        E:10
Huffman’s Code
3 .Take the first two vertices from the list and
  make them children of a vertex having the sum
  of their frequencies

                    *:8




             A:3            O:5
Huffman’s Code

4 .Insert the new vertex
   into the sorted list of
   vertices waiting to be
   put into tree                   T:7   E:10
• List of remaining
   vertices
• New list, with the
   new vertex                T:7   8     E:10
    inserted
Huffman’s Code

                                  *: 15
5. Take the first 2
   vertices from the list
   and make them            T:7           *: 8
Children of the vertex
   having the sum of
   their frequencies.
                                    A:3          O:5
Huffman’s Code
6. Insert the new vertex into the sorted list of vertices
   waiting to be put into tree.

• List of remaining vertices                         E:10



• New list, with the                  E:10          * : 15
  new vertex
   inserted
*:25      New vertex with
                                      frequency 10 +15 = 25


7. Take the
                     E:10          *:15
first two
Vertices from
the list and make
them children of             T:7             *:8
 the vertex having
 the sum of their
   frequencies.
                                    A:3                  O:5
Huffman’
                            *:25
  s Code               0           1

                     E:10          *:15
• Left branch = 0                         1
                              0
• Right branch = 1
• Huffman Code
                             T:7          *:8
E:0
T:10                                            1
                                     0
A:110
O: 111                              A:3         O:5
Advantage of
               Huffman Codes
• Reduce size of data by 20%-90% in general
• If no characters occur more frequently than others,
  then no advantage over ASCII.
• Encoding:
  –Given the characters and their frequencies, perform
  the algorithm and generate a code. Write the
  characters using the code.
• Decoding:
  Given the Huffman tree, figure out what each
  character is (possible because of prefix property).
Applications
• Both the .mp3 and .jpg file formats use
  Huffman coding at one stage of the compression.

• Alternative method that achieves higher
  compression but is slower is patented by IBM,
  making Huffman Codes attractively.
Program
References
•http://www.siggraph.org/education/materials/Hy
  perGraph/video/mpeg/mpegfaq/huffman_tutori
  al.html
• http://www.huffmancoding.com/david/algorith
  m.html

• http://www.cs.sfu.ca/CourseCentral/365/li/squ
  eeze/Huffman.htm
Data structures' project

More Related Content

PPT
Komdat-Kompresi Data
PPT
Data Structure and Algorithms Huffman Coding Algorithm
PPTX
Huffman Codes
PPTX
Huffman coding || Huffman Tree
PPT
DOC
Data structures project
PPTX
Simple Calendar Application using C
PPTX
DS_Final_Project
Komdat-Kompresi Data
Data Structure and Algorithms Huffman Coding Algorithm
Huffman Codes
Huffman coding || Huffman Tree
Data structures project
Simple Calendar Application using C
DS_Final_Project

Viewers also liked (20)

PPTX
Library management in Data structure
PPTX
Library Management System Project in C
PPTX
Project of data structure
PPTX
Calendar c
PPTX
Garrage management system
PPTX
чорнобиль
PPTX
PDF
JSP Project on Computer Shop Management System
PPTX
Presentation on mini dictionary using C language
PPTX
The Dictionary Project - Introduction
PPT
The Dictionary Project
PPTX
Ppt on atm machine
PPT
Library management system
PPTX
Library Management System PPT
DOCX
Software requirements specification of Library Management System
PPTX
Library management system
POTX
Library Management System
PDF
A project report on online trading
PPT
Library management system presentation
PPTX
ATM Banking
Library management in Data structure
Library Management System Project in C
Project of data structure
Calendar c
Garrage management system
чорнобиль
JSP Project on Computer Shop Management System
Presentation on mini dictionary using C language
The Dictionary Project - Introduction
The Dictionary Project
Ppt on atm machine
Library management system
Library Management System PPT
Software requirements specification of Library Management System
Library management system
Library Management System
A project report on online trading
Library management system presentation
ATM Banking
Ad

Similar to Data structures' project (20)

PDF
j001adcpresentation-2112170415 23.pdf
PPTX
Huffman Algorithm and its Application by Ekansh Agarwal
PPTX
Farhana shaikh webinar_huffman coding
PDF
Module-IV 094.pdf
PDF
Data communication & computer networking: Huffman algorithm
PPT
Greedy Algorithms Huffman Coding.ppt
PPTX
Huffman.Encodingpptx Variable length coding
PPTX
Huffman's algorithm in Data Structure
PPTX
Huffman coding || Huffman Tree
PPTX
Huffman tree
PDF
Huffman Encoding Pr
PDF
Huffman
PDF
Huffman
PPTX
Lecture 02 lexical analysis
DOCX
Huffman Coding is a technique of compressing data
PPTX
Huffman's Alforithm
PPT
Huffman coding presentation Sukkur iba.ppt
PPTX
Huffman codes
PPTX
Huffman.pptx
PPT
Huffman > Data Structures & Algorithums
j001adcpresentation-2112170415 23.pdf
Huffman Algorithm and its Application by Ekansh Agarwal
Farhana shaikh webinar_huffman coding
Module-IV 094.pdf
Data communication & computer networking: Huffman algorithm
Greedy Algorithms Huffman Coding.ppt
Huffman.Encodingpptx Variable length coding
Huffman's algorithm in Data Structure
Huffman coding || Huffman Tree
Huffman tree
Huffman Encoding Pr
Huffman
Huffman
Lecture 02 lexical analysis
Huffman Coding is a technique of compressing data
Huffman's Alforithm
Huffman coding presentation Sukkur iba.ppt
Huffman codes
Huffman.pptx
Huffman > Data Structures & Algorithums
Ad

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPT
Geologic Time for studying geology for geologist
PDF
Getting Started with Data Integration: FME Form 101
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Architecture types and enterprise applications.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
What is a Computer? Input Devices /output devices
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
CloudStack 4.21: First Look Webinar slides
PDF
August Patch Tuesday
PDF
STKI Israel Market Study 2025 version august
PPTX
Tartificialntelligence_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Final SEM Unit 1 for mit wpu at pune .pptx
Group 1 Presentation -Planning and Decision Making .pptx
Geologic Time for studying geology for geologist
Getting Started with Data Integration: FME Form 101
Zenith AI: Advanced Artificial Intelligence
observCloud-Native Containerability and monitoring.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
A review of recent deep learning applications in wood surface defect identifi...
sustainability-14-14877-v2.pddhzftheheeeee
Architecture types and enterprise applications.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
A comparative study of natural language inference in Swahili using monolingua...
What is a Computer? Input Devices /output devices
Univ-Connecticut-ChatGPT-Presentaion.pdf
CloudStack 4.21: First Look Webinar slides
August Patch Tuesday
STKI Israel Market Study 2025 version august
Tartificialntelligence_presentation.pptx

Data structures' project

  • 2. COMSATS Institute of Information & Technology, Islamabad Subject : Data Structures A presentation by Ayesha Arif FA10-BSB-014 & Ghazanfar Ali Baig FA10-BSB-024 Instructor Name: Ms. Nusrat Shaheen
  • 4. Background • When we encode characters in computers, we assign each an 8-bit code based on an ASCII chart. • But in most files, some characters appear more often than others. • So wouldn't it make more sense to assign shorter codes for characters that appear more often and longer codes for characters that appear less often?
  • 5. Data Compressions • Lossless compressions: Less space is used, or energy to transmit it. –No information is lost –we can reconstruct the original text –Often: be able to quickly reconstruct original text • Lossy compressions.
  • 6. Data Compressions • Text representation: • ASCII: 1 byte per character (fixed length code) – “M A R C” 1st Byte 2nd Byte 3rd Byte 4th byte 77 97 114 99 01001101 01100001 01110010 01100011
  • 7. • In the English language, the letter „e‟ is, „quite common x‟ is less common–Why should all characters be represented using the same number of bits?
  • 8. Huffman • 1951, David Huffman found the “most efficient method of representing numbers, letters, and other symbols using binary code” • Now standard method used for data compression
  • 9. The Concept • Huffman coding has the following properties: • Codes for more probable characters are shorter than ones for less probable characters. • Each code can be uniquely decoded .
  • 10. The Concept • To read the codes from a Huffman tree, start from the root and add a '0' every time you go left to a child, and add a '1' every time you go right. So in this example, the code for the character 'b' is 01 and the code for 'd' is 110. • As you can see, 'a' has a shorter code than 'd'. Notice that since all the characters are at the leafs of the tree (the ends), there is never a chance that one code will be the prefix of another one (eg. 'a' is 00 and 'b' is 011 • ). • Hence, this unique prefix property assures that each code can be uniquely decoded.
  • 11. Huffman Codes • How to construct Huffman codes? • Build a binary tree!
  • 12. Binary Tree • A binary tree is a tree where each internal node has at most 2 children.
  • 13. Internal The “Root Node” A Vertex The “Left Node” B C The “Right Node” D E F G Sibling Nodes Leaf Binary Tree Vertex
  • 14. Algorithm 1.Take the characters and their frequencies, and this list by increasing frequency. 2 .All the characters are vertices of the tree. 3.Take the first 2 vertices from the list and make them children of a vertex having the sum of their frequencies. 4.Insert the new vertex into the sorted list of vertices waiting to be put into the tree. 5.If there are at least 2 vertices in the list, go to step 3. 6.Read the Huffman code from the tree.
  • 15. Huffman’s Code 1.Take the characters and their frequencies, and sort this list by increasing frequency A: 3, O: 5, T: 7, E:10
  • 16. Huffman’s Code 2. All the characters are the vertices of the tree: A:3 O:5 T:7 E:10
  • 17. Huffman’s Code 3 .Take the first two vertices from the list and make them children of a vertex having the sum of their frequencies *:8 A:3 O:5
  • 18. Huffman’s Code 4 .Insert the new vertex into the sorted list of vertices waiting to be put into tree T:7 E:10 • List of remaining vertices • New list, with the new vertex T:7 8 E:10 inserted
  • 19. Huffman’s Code *: 15 5. Take the first 2 vertices from the list and make them T:7 *: 8 Children of the vertex having the sum of their frequencies. A:3 O:5
  • 20. Huffman’s Code 6. Insert the new vertex into the sorted list of vertices waiting to be put into tree. • List of remaining vertices E:10 • New list, with the E:10 * : 15 new vertex inserted
  • 21. *:25 New vertex with frequency 10 +15 = 25 7. Take the E:10 *:15 first two Vertices from the list and make them children of T:7 *:8 the vertex having the sum of their frequencies. A:3 O:5
  • 22. Huffman’ *:25 s Code 0 1 E:10 *:15 • Left branch = 0 1 0 • Right branch = 1 • Huffman Code T:7 *:8 E:0 T:10 1 0 A:110 O: 111 A:3 O:5
  • 23. Advantage of Huffman Codes • Reduce size of data by 20%-90% in general • If no characters occur more frequently than others, then no advantage over ASCII. • Encoding: –Given the characters and their frequencies, perform the algorithm and generate a code. Write the characters using the code. • Decoding: Given the Huffman tree, figure out what each character is (possible because of prefix property).
  • 24. Applications • Both the .mp3 and .jpg file formats use Huffman coding at one stage of the compression. • Alternative method that achieves higher compression but is slower is patented by IBM, making Huffman Codes attractively.
  • 26. References •http://www.siggraph.org/education/materials/Hy perGraph/video/mpeg/mpegfaq/huffman_tutori al.html • http://www.huffmancoding.com/david/algorith m.html • http://www.cs.sfu.ca/CourseCentral/365/li/squ eeze/Huffman.htm