SlideShare a Scribd company logo
Welcome to Our Presentation
Presentation Topic: Greedy Algorithm
Group Members:
Name: Arifur Jaman Bappy ID: 153-15-607
Name: Mohammad Salim Hosen ID: 162-15-1044
Name: Md Rifat Rahman ID: 162-15-1049
What is Greedy Algorithm
A greedy algorithm is an algorithm that follows the
problem solving approach of making the locally optimal
choice at each stage with the hope of finding a global
optimum solution.
Pros and Cons of Greedy Algorithm
• Pros:
• Simple, Easy to Implement, Run Fast
• Cons:
• Very often they don’t provide global optimum solution.
When to use Greedy Algorithm
1. Greedy – choice property: When a global optimum
can be arrived by selecting local optimum
2. Optimal Substructure: An optimal solution to the
problem contains optimal solution to subproblems.
Greedy Algorithms We Will Discuss
• Greedy Coin Change Algorithm
• Greedy Fractional Knapsack Algorithm
• Greedy Huffman Algorithm
Greedy Algorithm to find Minimum number of Coins
Give
me $35
$5 $10 $20
You may give:
5+5+5+5+5+5+5
10+5+5+5+5+5
20+5+5+5
……………………
Greedy Coin Change Algorithm
• V = Given value to make change
• C = Largest coin no longer than V
• I = Number of Denomination
• T = Total Number of coins initially 0
1. while V>0
2. if C[i] <= V
3. num = V/C[i];
4. V = V-(num*C[i]);
5. T += num;
6. i = i – 1;
Greedy Coin Change Algorithm
Algorithm:
1. while V>0
2. if C[i] <= V
3. num = V/C[i];
4. V = V-(num*C[i]);
5. T += num;
6. i = i – 1;
Coins: $5, $10, $20
V = $35, i = 3, T = 0
Is $35 greater than 0 Yes
Is $20 less than or equal $35 Yes
num is $35/$20 = 1
Amount Left in V is $35 - $20 = $15
Total coin T is 0+1 = 1
i = 3-1 = 2
Greedy Coin Change Algorithm
Algorithm:
1. while V>0
2. if C[i] <= V
3. num = V/C[i];
4. V = V-(num*C[i]);
5. T += num;
6. i = i – 1;
Coins: $5, $10, $20
V = $15, i = 2
Is $15 greater than 0 Yes
Is $10 less than or equal $15 Yes
Num is $15/$10 = 1
Amount Left in V is $15 - $10 = $5
Total coin T is 1+1 = 2
i = 2-1 = 1
Greedy Coin Change Algorithm
Algorithm:
1. while V>0
2. if C[i] <= V
3. num = V/C[i];
4. V = V-(num*C[i]);
5. T += num;
6. i = i – 1;
Coins: $5, $10, $20
V = $5, i = 1
Is $5 greater than 0 Yes
Is $5 less than or equal $5 Yes
Num is $5/$5 = 1
Amount Left in V is $5 - $5 = $0
Total coin is 2+1 = 3
i = 1-1 = 0 So 3 Coin will be needed to make $35
Fractional Knapsack
• If we are allowed to take fractional amounts,
then this is the fractional knapsack problem.
• Goal: Choose items with maximum total benefit
but with weight at most total weight.
Fractional Knapsack
6 kg
Bronze – 3kg Silver – 2kg
Gold – 4kg
Platinum – 1kg
Diamond – 5kg
Fractional Knapsack
Item Bronze Silver Platinum Gold Diamond
Value ($) 25 20 15 40 50
Weight (kg) 3 2 1 4 5
Value/Weight 8.3 10 15 10 10
Item Taken Weight Value
Platinum 1 kg $15
Silver 2 kg $20
Gold 3 kg $30
Total: 3 Item 6 kg $65
Huffman Coding
Character Code Frequency Total Bits
A 000 10 30
E 001 15 45
I 010 12 36
S 011 3 9
T 100 4 12
P 101 13 39
Newline 110 1 3
TOTAL: 174
• Our Goal is to reduce total number of bits without losing any information.
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
4
n S
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
4
n S
8
T
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
Node 18 18
4
n S
8
T
18
A
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
Node 18 18
Node 25 25
I
25
P
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
Node 18 18
Node 25 25
Node 33 33
4
n S
8
T
18
A
33
E
Huffman Algorithm
Character Frequency
n 1
S 3
T 4
A 10
I 12
P 13
E 15
Node 18 18
Node 25 25
Node 33 33
4
n S
8
T
18
A
33
E
I
25
P
58
Huffman Algorithm
Character Code
A 111
E 10
I 00
S 11001
T 1101
P 01
Newline 11000
4
n S
8
T
18
A
33
E
I
25
P
58
0
0 1
1
0 1
0 1
1
0
0 1
Result:
Character Code Frequency Total Bits
A 111 10 30
E 10 15 30
I 00 12 24
S 11001 3 15
T 1101 4 16
P 01 13 26
Newline 11000 1 5
TOTAL: 146
Total bits reduced to 146 from 176 without losses of any data.
Presentation on Greedy Algorithm

More Related Content

Similar to Presentation on Greedy Algorithm

Karatbars Presentation
Karatbars PresentationKaratbars Presentation
Karatbars PresentationDavid Koen
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
mikscott
 
fidleink
fidleinkfidleink
fidleink
mikscott
 
Cvv
CvvCvv
fidleink13
fidleink13fidleink13
fidleink13
mikscott
 
dumps for sale
dumps for saledumps for sale
dumps for sale
mikscott
 
this is the best you can get
this is the best you can getthis is the best you can get
this is the best you can get
mikscott
 
Stuff I Learned About Performance
Stuff I Learned About PerformanceStuff I Learned About Performance
Stuff I Learned About Performance
Michael Barker
 
BIZ
BIZBIZ
Increasing reporting value with statistics
Increasing reporting value with statisticsIncreasing reporting value with statistics
Increasing reporting value with statisticsvraopolisetti
 
good dumps
good dumpsgood dumps
good dumps
mikscott
 
Double
Double Double
Double
mikscott
 
Double
Double Double
Double
mikscott
 
legit bank transaction
legit bank transactionlegit bank transaction
legit bank transaction
mikscott
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
mikscott
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
mikscott
 
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
Xue Xin Tsai
 
November meeting - ROC
November meeting - ROCNovember meeting - ROC
November meeting - ROC
themechanicalbear
 
Karatbars Presentation (english)
Karatbars Presentation (english)Karatbars Presentation (english)
Karatbars Presentation (english)
Karatbars International
 
Tiny encryption algorithm
Tiny encryption algorithmTiny encryption algorithm
Tiny encryption algorithm
Farah M. Altufaili
 

Similar to Presentation on Greedy Algorithm (20)

Karatbars Presentation
Karatbars PresentationKaratbars Presentation
Karatbars Presentation
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
 
fidleink
fidleinkfidleink
fidleink
 
Cvv
CvvCvv
Cvv
 
fidleink13
fidleink13fidleink13
fidleink13
 
dumps for sale
dumps for saledumps for sale
dumps for sale
 
this is the best you can get
this is the best you can getthis is the best you can get
this is the best you can get
 
Stuff I Learned About Performance
Stuff I Learned About PerformanceStuff I Learned About Performance
Stuff I Learned About Performance
 
BIZ
BIZBIZ
BIZ
 
Increasing reporting value with statistics
Increasing reporting value with statisticsIncreasing reporting value with statistics
Increasing reporting value with statistics
 
good dumps
good dumpsgood dumps
good dumps
 
Double
Double Double
Double
 
Double
Double Double
Double
 
legit bank transaction
legit bank transactionlegit bank transaction
legit bank transaction
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
 
Cvv222222
Cvv222222Cvv222222
Cvv222222
 
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
Swifter Taipei 聊聊 Swift 遊樂場、變數常數、數字與運算
 
November meeting - ROC
November meeting - ROCNovember meeting - ROC
November meeting - ROC
 
Karatbars Presentation (english)
Karatbars Presentation (english)Karatbars Presentation (english)
Karatbars Presentation (english)
 
Tiny encryption algorithm
Tiny encryption algorithmTiny encryption algorithm
Tiny encryption algorithm
 

More from Salim Hosen

Restaurant management system
Restaurant management systemRestaurant management system
Restaurant management system
Salim Hosen
 
Presentation on computer ram
Presentation on computer ramPresentation on computer ram
Presentation on computer ram
Salim Hosen
 
Presentation on Bio Informatics
Presentation on Bio InformaticsPresentation on Bio Informatics
Presentation on Bio Informatics
Salim Hosen
 
Presentation on iot restaurant project
Presentation on iot restaurant projectPresentation on iot restaurant project
Presentation on iot restaurant project
Salim Hosen
 
Famous Quotes of Famous People
Famous Quotes of Famous PeopleFamous Quotes of Famous People
Famous Quotes of Famous People
Salim Hosen
 
Presentation on IOT (Internet Of Things)
Presentation on IOT (Internet Of Things)Presentation on IOT (Internet Of Things)
Presentation on IOT (Internet Of Things)
Salim Hosen
 
Presentation on Graph
Presentation on GraphPresentation on Graph
Presentation on Graph
Salim Hosen
 
Presentation on Variance
Presentation on VariancePresentation on Variance
Presentation on Variance
Salim Hosen
 
Presentation on Digital Image Processing
Presentation on Digital Image ProcessingPresentation on Digital Image Processing
Presentation on Digital Image Processing
Salim Hosen
 
Intellectual Property Presentation
Intellectual Property PresentationIntellectual Property Presentation
Intellectual Property Presentation
Salim Hosen
 
Android Studio Overview
Android Studio OverviewAndroid Studio Overview
Android Studio Overview
Salim Hosen
 
Presentation Data Link Layer and Network Layer
Presentation Data Link Layer and Network LayerPresentation Data Link Layer and Network Layer
Presentation Data Link Layer and Network Layer
Salim Hosen
 
Presentation on RAM
Presentation on RAMPresentation on RAM
Presentation on RAM
Salim Hosen
 
Presentation on BJT
Presentation on BJTPresentation on BJT
Presentation on BJT
Salim Hosen
 
Application of Differential Equation
Application of Differential EquationApplication of Differential Equation
Application of Differential Equation
Salim Hosen
 
Presentation on Relational Schema (Database)
Presentation on Relational Schema (Database)Presentation on Relational Schema (Database)
Presentation on Relational Schema (Database)
Salim Hosen
 
Intellectual property
Intellectual propertyIntellectual property
Intellectual property
Salim Hosen
 

More from Salim Hosen (17)

Restaurant management system
Restaurant management systemRestaurant management system
Restaurant management system
 
Presentation on computer ram
Presentation on computer ramPresentation on computer ram
Presentation on computer ram
 
Presentation on Bio Informatics
Presentation on Bio InformaticsPresentation on Bio Informatics
Presentation on Bio Informatics
 
Presentation on iot restaurant project
Presentation on iot restaurant projectPresentation on iot restaurant project
Presentation on iot restaurant project
 
Famous Quotes of Famous People
Famous Quotes of Famous PeopleFamous Quotes of Famous People
Famous Quotes of Famous People
 
Presentation on IOT (Internet Of Things)
Presentation on IOT (Internet Of Things)Presentation on IOT (Internet Of Things)
Presentation on IOT (Internet Of Things)
 
Presentation on Graph
Presentation on GraphPresentation on Graph
Presentation on Graph
 
Presentation on Variance
Presentation on VariancePresentation on Variance
Presentation on Variance
 
Presentation on Digital Image Processing
Presentation on Digital Image ProcessingPresentation on Digital Image Processing
Presentation on Digital Image Processing
 
Intellectual Property Presentation
Intellectual Property PresentationIntellectual Property Presentation
Intellectual Property Presentation
 
Android Studio Overview
Android Studio OverviewAndroid Studio Overview
Android Studio Overview
 
Presentation Data Link Layer and Network Layer
Presentation Data Link Layer and Network LayerPresentation Data Link Layer and Network Layer
Presentation Data Link Layer and Network Layer
 
Presentation on RAM
Presentation on RAMPresentation on RAM
Presentation on RAM
 
Presentation on BJT
Presentation on BJTPresentation on BJT
Presentation on BJT
 
Application of Differential Equation
Application of Differential EquationApplication of Differential Equation
Application of Differential Equation
 
Presentation on Relational Schema (Database)
Presentation on Relational Schema (Database)Presentation on Relational Schema (Database)
Presentation on Relational Schema (Database)
 
Intellectual property
Intellectual propertyIntellectual property
Intellectual property
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 

Presentation on Greedy Algorithm

  • 1. Welcome to Our Presentation Presentation Topic: Greedy Algorithm
  • 2. Group Members: Name: Arifur Jaman Bappy ID: 153-15-607 Name: Mohammad Salim Hosen ID: 162-15-1044 Name: Md Rifat Rahman ID: 162-15-1049
  • 3. What is Greedy Algorithm A greedy algorithm is an algorithm that follows the problem solving approach of making the locally optimal choice at each stage with the hope of finding a global optimum solution.
  • 4. Pros and Cons of Greedy Algorithm • Pros: • Simple, Easy to Implement, Run Fast • Cons: • Very often they don’t provide global optimum solution.
  • 5. When to use Greedy Algorithm 1. Greedy – choice property: When a global optimum can be arrived by selecting local optimum 2. Optimal Substructure: An optimal solution to the problem contains optimal solution to subproblems.
  • 6. Greedy Algorithms We Will Discuss • Greedy Coin Change Algorithm • Greedy Fractional Knapsack Algorithm • Greedy Huffman Algorithm
  • 7. Greedy Algorithm to find Minimum number of Coins Give me $35 $5 $10 $20 You may give: 5+5+5+5+5+5+5 10+5+5+5+5+5 20+5+5+5 ……………………
  • 8. Greedy Coin Change Algorithm • V = Given value to make change • C = Largest coin no longer than V • I = Number of Denomination • T = Total Number of coins initially 0 1. while V>0 2. if C[i] <= V 3. num = V/C[i]; 4. V = V-(num*C[i]); 5. T += num; 6. i = i – 1;
  • 9. Greedy Coin Change Algorithm Algorithm: 1. while V>0 2. if C[i] <= V 3. num = V/C[i]; 4. V = V-(num*C[i]); 5. T += num; 6. i = i – 1; Coins: $5, $10, $20 V = $35, i = 3, T = 0 Is $35 greater than 0 Yes Is $20 less than or equal $35 Yes num is $35/$20 = 1 Amount Left in V is $35 - $20 = $15 Total coin T is 0+1 = 1 i = 3-1 = 2
  • 10. Greedy Coin Change Algorithm Algorithm: 1. while V>0 2. if C[i] <= V 3. num = V/C[i]; 4. V = V-(num*C[i]); 5. T += num; 6. i = i – 1; Coins: $5, $10, $20 V = $15, i = 2 Is $15 greater than 0 Yes Is $10 less than or equal $15 Yes Num is $15/$10 = 1 Amount Left in V is $15 - $10 = $5 Total coin T is 1+1 = 2 i = 2-1 = 1
  • 11. Greedy Coin Change Algorithm Algorithm: 1. while V>0 2. if C[i] <= V 3. num = V/C[i]; 4. V = V-(num*C[i]); 5. T += num; 6. i = i – 1; Coins: $5, $10, $20 V = $5, i = 1 Is $5 greater than 0 Yes Is $5 less than or equal $5 Yes Num is $5/$5 = 1 Amount Left in V is $5 - $5 = $0 Total coin is 2+1 = 3 i = 1-1 = 0 So 3 Coin will be needed to make $35
  • 12. Fractional Knapsack • If we are allowed to take fractional amounts, then this is the fractional knapsack problem. • Goal: Choose items with maximum total benefit but with weight at most total weight.
  • 13. Fractional Knapsack 6 kg Bronze – 3kg Silver – 2kg Gold – 4kg Platinum – 1kg Diamond – 5kg
  • 14. Fractional Knapsack Item Bronze Silver Platinum Gold Diamond Value ($) 25 20 15 40 50 Weight (kg) 3 2 1 4 5 Value/Weight 8.3 10 15 10 10 Item Taken Weight Value Platinum 1 kg $15 Silver 2 kg $20 Gold 3 kg $30 Total: 3 Item 6 kg $65
  • 15. Huffman Coding Character Code Frequency Total Bits A 000 10 30 E 001 15 45 I 010 12 36 S 011 3 9 T 100 4 12 P 101 13 39 Newline 110 1 3 TOTAL: 174 • Our Goal is to reduce total number of bits without losing any information.
  • 16. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 4 n S
  • 17. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 4 n S 8 T
  • 18. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 Node 18 18 4 n S 8 T 18 A
  • 19. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 Node 18 18 Node 25 25 I 25 P
  • 20. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 Node 18 18 Node 25 25 Node 33 33 4 n S 8 T 18 A 33 E
  • 21. Huffman Algorithm Character Frequency n 1 S 3 T 4 A 10 I 12 P 13 E 15 Node 18 18 Node 25 25 Node 33 33 4 n S 8 T 18 A 33 E I 25 P 58
  • 22. Huffman Algorithm Character Code A 111 E 10 I 00 S 11001 T 1101 P 01 Newline 11000 4 n S 8 T 18 A 33 E I 25 P 58 0 0 1 1 0 1 0 1 1 0 0 1
  • 23. Result: Character Code Frequency Total Bits A 111 10 30 E 10 15 30 I 00 12 24 S 11001 3 15 T 1101 4 16 P 01 13 26 Newline 11000 1 5 TOTAL: 146 Total bits reduced to 146 from 176 without losses of any data.

Editor's Notes

  1. In Slide Show mode, select the arrows to visit links.