SlideShare a Scribd company logo
1 of 20
Presentation
on
Greedy Algorithm (Optimal merge
pattern – Huffman coding)
Md. Monirul Alom - 162422011 (Group Leader)
Md. Moshiur Rahman Khan - 162422507
Md. Jahangir Alam - 162422004
Md. Rokan Uzzaman - 163432024
Md. Sanowar Hossain - 163432021
Md. Raisul Islam Ripon - 163432027
1
Greedy Algorithm
Greedy Algorithm finds the optimal solution from
the set of feasible solutions
2
X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
3
X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
Feasible solutions:
S3: Go by train
S4: Go by flight
8 hours
4
X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
Feasible solutions:
S3: Go by train
S4: Go by flight
Optimal Solution:
S3: Go by train (Costs less)
5
Optimal merge pattern
A B
3 5
8 9
12 11
20 16
C
3
5
8
9
11
12
16
20
m n
4 4
Complexity: ϴ(m+n) = 8
6
List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
11
13
16
Cost = 11+13+16 = 40
7
List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
11 5
16
Cost = 11+5+16 = 32
8
List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
16
10
5
Cost = 5+10+16 = 31
9
List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
E
7
Sorted in ascending order
10
List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
E
7
5
10
23
13
11
List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
Cost
5+10+13+23 = 51
E
7
5
10
23
13
2*3+3*3+5*2+6*2+7*2 = 51
12
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
Character
A
B
C
D
E
Length: 20
Size: 20*8 = 160 bits
13
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
Character
Code
A 000
B 001
C 010
D 011
E 100
Length: 20
Size: 20*3 = 60 bits
001010010000………
14
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
Character
Code
A 000
B 001
C 010
D 011
E 100
40
bits
15
bits
55 bits
Length: 20
Size: 20*3 = 60 bits
001010010000………
Total size = 60 +55
= 115 bits
15
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
Character
Frequency
A 3
B 5
C 6
D 4
E 2
2 3 4 5 6
E A D B C
Sorted in ascending order according to frequency
16
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
2 3 4 5 6
E A D B C
5
9
11
20
Character
Frequency
A 3
B 5
C 6
D 4
E 2
17
Huffman Coding
Message: BCCABBDDAECCBBAEDDCC
Character
Frequency
Code
A 3 001 3*3= 9
B 5 10 5*2=10
C 6 11 6*2=12
D 4 01 4*2=8
E 2 000 2*3=6
40
bits
20 12
bits
45 bits
2 3 4 5 6
E A D B C
5
9
11
200
0
0
0
1
11
1
Total = Message + table
= 45 + 52 = 97 bits
18
Decoding
Message: BCCABBDDAECCBBAEDDCC
2 3 4 5 6
E A D B C
5
9
11
200
0
0
0
1
11
1
101111001……..
19
Thank you
20

More Related Content

What's hot

All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 

What's hot (20)

Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Rc4
Rc4Rc4
Rc4
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
RSA ALGORITHM
RSA ALGORITHMRSA ALGORITHM
RSA ALGORITHM
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Image encryption and decryption
Image encryption and decryptionImage encryption and decryption
Image encryption and decryption
 
Cryptography and Information Security
Cryptography and Information SecurityCryptography and Information Security
Cryptography and Information Security
 
Array ppt
Array pptArray ppt
Array ppt
 
Rail-Fence Cipher Presentation
Rail-Fence Cipher PresentationRail-Fence Cipher Presentation
Rail-Fence Cipher Presentation
 
Diffiehellman
DiffiehellmanDiffiehellman
Diffiehellman
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Public Key Cryptography
Public Key CryptographyPublic Key Cryptography
Public Key Cryptography
 

Similar to Greedy Algorithm - Huffman coding

Year 10 end of year exam revision 2
Year 10 end of year exam revision 2Year 10 end of year exam revision 2
Year 10 end of year exam revision 2
harpermaths
 

Similar to Greedy Algorithm - Huffman coding (15)

Situational-Problem-Involving-Conic-Sections.pptx
Situational-Problem-Involving-Conic-Sections.pptxSituational-Problem-Involving-Conic-Sections.pptx
Situational-Problem-Involving-Conic-Sections.pptx
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
MD5 - Hash Functions & RIPEMD160
MD5 - Hash Functions & RIPEMD160MD5 - Hash Functions & RIPEMD160
MD5 - Hash Functions & RIPEMD160
 
Hash functions MD5 and RIPEMD 160
Hash functions MD5 and RIPEMD 160Hash functions MD5 and RIPEMD 160
Hash functions MD5 and RIPEMD 160
 
solution manual Design of Machinery: An Introduction to the Synthesis and Ana...
solution manual Design of Machinery: An Introduction to the Synthesis and Ana...solution manual Design of Machinery: An Introduction to the Synthesis and Ana...
solution manual Design of Machinery: An Introduction to the Synthesis and Ana...
 
Gate ee 2012 with solutions
Gate ee 2012 with solutionsGate ee 2012 with solutions
Gate ee 2012 with solutions
 
MathsX.pdf
MathsX.pdfMathsX.pdf
MathsX.pdf
 
Đề Thi HK2 Toán 8 - THCS Hùng Vương
Đề Thi HK2 Toán 8 - THCS Hùng VươngĐề Thi HK2 Toán 8 - THCS Hùng Vương
Đề Thi HK2 Toán 8 - THCS Hùng Vương
 
Đề Thi HK2 Toán 8 - THCS Hùng Vương
Đề Thi HK2 Toán 8 - THCS Hùng VươngĐề Thi HK2 Toán 8 - THCS Hùng Vương
Đề Thi HK2 Toán 8 - THCS Hùng Vương
 
Exams in college algebra
Exams in college algebraExams in college algebra
Exams in college algebra
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
What is a polynomial
What is a polynomialWhat is a polynomial
What is a polynomial
 
Year 10 end of year exam revision 2
Year 10 end of year exam revision 2Year 10 end of year exam revision 2
Year 10 end of year exam revision 2
 
Presentation (7).pptx
Presentation (7).pptxPresentation (7).pptx
Presentation (7).pptx
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

Greedy Algorithm - Huffman coding