SlideShare a Scribd company logo
1 of 27
Design and
Analysis of
Algorithms
GREEDY METHOD
KRUSKAL’S ALGORITHM USING UNION FIND
MINIMUM SPANNING TREE
GREEDY ALGORITHMS AND MATROIDS
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Greedy Algorithms 2
LOGISTICS
CS 6212
Analysis
Asymptotic
NP-
Completeness
Design
D&C
Greedy
DP
Graph
B&B
Applications
Algorithms Greedy Algorithms 3
WHERE WE ARE
 Done
 Done
 Starting today..
 A technique to build a complete solution by making a
sequence of “best selection” steps
 Selection depends upon actual problem
 Focus is simply on “what is best step from this point”
Algorithms Greedy Algorithms 4
GREEDY METHOD
 Applications of greedy method are very broad.
 Examples:
 Sorting
 Merging sorted lists
 Knapsack
 Minimum Spanning Tree (MST)
 Hoffman Encoding
Algorithms Greedy Algorithms 5
APPLICATIONS
 Select the minimum element
 Move it to the beginning
 Continue doing it for the remaining array
Given array a[1..n] of unsorted numbers
 For i = 1 to n-1
 For j = i+1 to n
 If (a[i] > a[j]) swap (a[i], a[j])
Algorithms Greedy Algorithms 6
SORTING USING GREEDY METHOD
 How long does it take to sort using greedy method?
 Is it optimal?
Algorithms Greedy Algorithms 7
TIME COMPLEXITY ANALYSIS
 Input: n sorted arrays of lengths
L[1], L[2],...,L[n]
 Problem: To merge all the arrays into one array as
fast as possible. Which pair to merge every time?
 We observe that:
 The final list will be a list of length L[1] + L[2] + … + L[n]
 The final list will be same regardless of the sequence in which
we merge lists
 However, the time taken may not be the same.
Algorithms Greedy Algorithms 8
MERGING SORTED LISTS
 Greedy method: Merge the two shortest remaining
arrays.
 To Implement, we can keep a data structure, that
allows us to:
 Remove the two smallest arrays
 Add a larger array
 Keep doing this until we have one array
Algorithms Greedy Algorithms 9
MERGING SORTED LISTS
 Implement using heap
 Build the original heap – O(n) time
 For i = 1 to n-1
 Remove two smallest elements: 2 log (n)
 Add a new element log(n) time
 Total time: O(n log n)
Algorithms Greedy Algorithms 10
MERGING SORTED LISTS
 Input: A weight capacity C, and n items of weights W[1:n] and
monetary value V[1:n].
 Problem: Determine which items to take and how much of
each item so that the total weight is ≤ C, and the total value
(profit) is maximized.
 Formulation of the problem: Let x[i] be the fraction taken
from item i. 0 ≤ x[i] ≤ 1.
The weight of the part taken from item i is x[i]*W[i]
The Corresponding profit is x[i]*V[i]
 The problem is then to find the values of the array x[1:n] so
that x[1]V[1] + x[2]V[2] + ... + x[n]V[n] is maximized subject to
the constraint that x[1]W[1] + x[2]W[2] + ... + x[n]W[n] ≤ C
Algorithms Greedy Algorithms 11
KNAPSACK PROBLEM
Algorithms Greedy Algorithms 12
3 options
Policy 1: Choose the lightest
remaining item, and take as
much of it as can fit.
Policy 2: Choose the most
profitable remaining item,
and take as much of it as
can fit.
Policy 3: Choose the item
with the highest price per
unit weight (V[i]/W[i]), and
take as much of it as can fit.
Exercise: Prove by a counter example that Policy 1 does
not guarantee an optimal solution. Same with Policy 2.
Policy 3 always gives an optimal solution
Capacity = 7
Solution:
1. All of items {1, 2} and a fraction of item 3
2. But, how to handle this problem instance if we
cannot take “fractional” portions of items.
Algorithms Greedy Algorithms 13
EXAMPLE
Item # 1 2 3 4 5
V ($) 3 5 10 11 9
W (lb) 1 2 5 6 7
V/W 3 2.5 2 1.83 1.28
 No, in fact, it can be as bad as you want to make it
to be.
 Example?
 A simple fix can make this algorithm only as bad as
a ratio of 2.
 How?
Algorithms Greedy Algorithms 14
IS GREEDY ALGORITHM FOR INTEGER
KNAPSACK PROBLEM OPTIMAL?
 Definitions
 A spanning tree of a graph is a tree that has all nodes in the
graph, and all edges come from the graph
 Weight of tree = Sum of weights of edges in the tree
 Statement of the MST problem
 Input : a weighted connected graph G=(V,E). The weights are
represented by the 2D array (matrix) W[1:n,1:n], where W[i,j] is
the weight of edge (i,j).
 Output: Find a minimum-weight spanning tree of G.
Algorithms Greedy Algorithms 15
MINIMUM SPANNING TREE
 Selection Policy: Minimum weighted edge that
does NOT create a cycle.
 Procedure ComputeMST(in:G, W[1:n,1:n]; out:T)
Sort edges: e[1], e[2], .. e[m].
Initialize counter j = 1
Initialize tree T to empty
While (number of edges in Tree < n-1) {
Does adding an edge e[j] create a cycle?
If No, add edge e[j] to tree T
}
Algorithms Greedy Algorithms 16
GREEDY ALGORITHM
Sort edges: e[1], e[2], .. e[m].
Initialize counter j = 1
Initialize tree T to empty
While (number of edges in Tree < n-1) {
Does adding an edge e[j] create a cycle?
If No, add edge e[j] to tree T
}
Algorithms Greedy Algorithms 17
HOW TO MAKE THIS EFFICIENT?
Each set is marked by a leader
When calling “find” on a set’s member, it
returns the leader
Leader maintains a rank (or height)
When doing a union, make the tree with
smaller height (or rank) to be a child of the
tree with the larger height
Note that this is NOT a binary tree.
Algorithms Greedy Algorithms 18
UNION FIND DATA STRUCTURE
 When doing a find, follow that up by compressing the
path to the root, by making every node (along the
way) point to the root.
 This is not easy to prove, but Union Find with Path
compression, when starting with n nodes and m
operations, takes O(m log*(n)) time instead of O(m
log n) time, where the log* function is the iterated
logarithm (also called the super logarithm) and is an
extremely slow growing function.
 log*(n) is defined as follows:
 0, if n <= 1
 1 + log*(log n) if n > 1
Algorithms Greedy Algorithms 19
UNION FIND – PATH COMPRESSION
 Using 2 Find operations to check if adding an edge
will create a cycle or not.
 When adding an edge, use a Union Operation
Algorithms Greedy Algorithms 20
TIME COMPLEXITY ANALYSIS OF KRUSKAL’S
ALGORITHM
 Proof by contradiction
Algorithms Greedy Algorithms 21
WHY DOES KRUSKAL’S ALGORITHM WORK?
 Optimal Substructure Property: A problem has
optimal substructure if an optimal solution to the
problem contains within it optimal solutions to
its sub problems.
 Greedy Choice Property: If a local greedy choice is
made, then an optimal solution including this choice
is possible.
Algorithms Greedy Algorithms 22
TWO BASIC PROPERTIES OF OPTIMAL
GREEDY ALGORITHMS
 A subset system is a set E together with a set of
subsets of E, called I, such that I is closed under
inclusion. This means that if X ⊆ Y and Y ∈ I, then X
∈ I. (I is sometimes referred to as set of
independent sets.)
 A subset system is a matroid if it satisfies the
exchange property: If i1 and i2 are sets in I and i1 has
fewer elements than i2, then there exists an element
e ∈ i2  i1 such that i1 ∪ {e} ∈ I.
 For any subset system (E,I), the greedy algorithm
solves the optimization problem for (E,I) if and only if
(E,I) is a matroid.
Algorithms Greedy Algorithms 23
GREEDY ALGORITHMS AND MATROIDS
 Prone to overuse
 You shouldn’t use this algorithm unless you can prove that the
solution is optimal.
 That is, no points in MT/Final for using greedy algorithm to
produce a suboptimal solution, where another algorithmic
technique (such as D&C) would have resulted in an optimal
solution.
 Why?
 Optimality has a “business value”. Suppose you are trying to
maximize the flights that you can schedule using 3 aircrafts.
 Time complexity merely represents a “cost of computation” of
that schedule.
 If one algorithm runs in 1 minute, but schedules only 7 flights,
and another algorithm runs in 2 hours, but schedules 8 flights,
which one would you use?
Algorithms Greedy Algorithms 24
WHEN NOT TO USE GREEDY ALGORITHM
 Chess
 Sorting
 Shortest path computation
 Knapsack
Algorithms Greedy Algorithms 25
GREEDY: TO APPLY OR NOT TO APPLY
CS 6212
Analysis
Asymptotic
NP-
Completeness
Design
D&C
Greedy
DP
Graph
B&B
Applications
Algorithms Greedy Algorithms 26
WHERE WE ARE
 Done
 Done
 Done
 Greedy
 Book – first problem on interval
scheduling classes
 http://en.wikipedia.org/wiki/Huffman_coding
 http://www.cs.kent.edu/~dragan/AdvAlg05/GreedyAlg-1x1.pdf
 Dynamic Programming
 Dynamic Programming: Book sections 6.1 – 6.4
 http://www.yaroslavvb.com/papers/wagner-dynamic.pdf
Algorithms Greedy Algorithms 27
READING ASSIGNMENT
Application # 5

More Related Content

What's hot

Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic ProgrammingFenil Shah
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 

What's hot (20)

Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
chapter 1
chapter 1chapter 1
chapter 1
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
Randomized Algorithm
Randomized AlgorithmRandomized Algorithm
Randomized Algorithm
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 

Similar to Greedy Algorithms

Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhhCh3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhhdanielgetachew0922
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notesProf. Dr. K. Adisesha
 
376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.pptRohitPaul71
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
final-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdffinal-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdfJasmineSayyed3
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESsuthi
 
UNIT-II.pptx
UNIT-II.pptxUNIT-II.pptx
UNIT-II.pptxJyoReddy9
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2debolina13
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introductionLow Ying Hao
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...TechVision8
 

Similar to Greedy Algorithms (20)

Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhhCh3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
final-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdffinal-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdf
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
 
UNIT-II.pptx
UNIT-II.pptxUNIT-II.pptx
UNIT-II.pptx
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
 
Ada notes
Ada notesAda notes
Ada notes
 

More from Amrinder Arora

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 

More from Amrinder Arora (20)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
NP completeness
NP completenessNP completeness
NP completeness
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 

Recently uploaded

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Greedy Algorithms

  • 1. Design and Analysis of Algorithms GREEDY METHOD KRUSKAL’S ALGORITHM USING UNION FIND MINIMUM SPANNING TREE GREEDY ALGORITHMS AND MATROIDS
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Greedy Algorithms 2 LOGISTICS
  • 4.  A technique to build a complete solution by making a sequence of “best selection” steps  Selection depends upon actual problem  Focus is simply on “what is best step from this point” Algorithms Greedy Algorithms 4 GREEDY METHOD
  • 5.  Applications of greedy method are very broad.  Examples:  Sorting  Merging sorted lists  Knapsack  Minimum Spanning Tree (MST)  Hoffman Encoding Algorithms Greedy Algorithms 5 APPLICATIONS
  • 6.  Select the minimum element  Move it to the beginning  Continue doing it for the remaining array Given array a[1..n] of unsorted numbers  For i = 1 to n-1  For j = i+1 to n  If (a[i] > a[j]) swap (a[i], a[j]) Algorithms Greedy Algorithms 6 SORTING USING GREEDY METHOD
  • 7.  How long does it take to sort using greedy method?  Is it optimal? Algorithms Greedy Algorithms 7 TIME COMPLEXITY ANALYSIS
  • 8.  Input: n sorted arrays of lengths L[1], L[2],...,L[n]  Problem: To merge all the arrays into one array as fast as possible. Which pair to merge every time?  We observe that:  The final list will be a list of length L[1] + L[2] + … + L[n]  The final list will be same regardless of the sequence in which we merge lists  However, the time taken may not be the same. Algorithms Greedy Algorithms 8 MERGING SORTED LISTS
  • 9.  Greedy method: Merge the two shortest remaining arrays.  To Implement, we can keep a data structure, that allows us to:  Remove the two smallest arrays  Add a larger array  Keep doing this until we have one array Algorithms Greedy Algorithms 9 MERGING SORTED LISTS
  • 10.  Implement using heap  Build the original heap – O(n) time  For i = 1 to n-1  Remove two smallest elements: 2 log (n)  Add a new element log(n) time  Total time: O(n log n) Algorithms Greedy Algorithms 10 MERGING SORTED LISTS
  • 11.  Input: A weight capacity C, and n items of weights W[1:n] and monetary value V[1:n].  Problem: Determine which items to take and how much of each item so that the total weight is ≤ C, and the total value (profit) is maximized.  Formulation of the problem: Let x[i] be the fraction taken from item i. 0 ≤ x[i] ≤ 1. The weight of the part taken from item i is x[i]*W[i] The Corresponding profit is x[i]*V[i]  The problem is then to find the values of the array x[1:n] so that x[1]V[1] + x[2]V[2] + ... + x[n]V[n] is maximized subject to the constraint that x[1]W[1] + x[2]W[2] + ... + x[n]W[n] ≤ C Algorithms Greedy Algorithms 11 KNAPSACK PROBLEM
  • 12. Algorithms Greedy Algorithms 12 3 options Policy 1: Choose the lightest remaining item, and take as much of it as can fit. Policy 2: Choose the most profitable remaining item, and take as much of it as can fit. Policy 3: Choose the item with the highest price per unit weight (V[i]/W[i]), and take as much of it as can fit. Exercise: Prove by a counter example that Policy 1 does not guarantee an optimal solution. Same with Policy 2. Policy 3 always gives an optimal solution
  • 13. Capacity = 7 Solution: 1. All of items {1, 2} and a fraction of item 3 2. But, how to handle this problem instance if we cannot take “fractional” portions of items. Algorithms Greedy Algorithms 13 EXAMPLE Item # 1 2 3 4 5 V ($) 3 5 10 11 9 W (lb) 1 2 5 6 7 V/W 3 2.5 2 1.83 1.28
  • 14.  No, in fact, it can be as bad as you want to make it to be.  Example?  A simple fix can make this algorithm only as bad as a ratio of 2.  How? Algorithms Greedy Algorithms 14 IS GREEDY ALGORITHM FOR INTEGER KNAPSACK PROBLEM OPTIMAL?
  • 15.  Definitions  A spanning tree of a graph is a tree that has all nodes in the graph, and all edges come from the graph  Weight of tree = Sum of weights of edges in the tree  Statement of the MST problem  Input : a weighted connected graph G=(V,E). The weights are represented by the 2D array (matrix) W[1:n,1:n], where W[i,j] is the weight of edge (i,j).  Output: Find a minimum-weight spanning tree of G. Algorithms Greedy Algorithms 15 MINIMUM SPANNING TREE
  • 16.  Selection Policy: Minimum weighted edge that does NOT create a cycle.  Procedure ComputeMST(in:G, W[1:n,1:n]; out:T) Sort edges: e[1], e[2], .. e[m]. Initialize counter j = 1 Initialize tree T to empty While (number of edges in Tree < n-1) { Does adding an edge e[j] create a cycle? If No, add edge e[j] to tree T } Algorithms Greedy Algorithms 16 GREEDY ALGORITHM
  • 17. Sort edges: e[1], e[2], .. e[m]. Initialize counter j = 1 Initialize tree T to empty While (number of edges in Tree < n-1) { Does adding an edge e[j] create a cycle? If No, add edge e[j] to tree T } Algorithms Greedy Algorithms 17 HOW TO MAKE THIS EFFICIENT?
  • 18. Each set is marked by a leader When calling “find” on a set’s member, it returns the leader Leader maintains a rank (or height) When doing a union, make the tree with smaller height (or rank) to be a child of the tree with the larger height Note that this is NOT a binary tree. Algorithms Greedy Algorithms 18 UNION FIND DATA STRUCTURE
  • 19.  When doing a find, follow that up by compressing the path to the root, by making every node (along the way) point to the root.  This is not easy to prove, but Union Find with Path compression, when starting with n nodes and m operations, takes O(m log*(n)) time instead of O(m log n) time, where the log* function is the iterated logarithm (also called the super logarithm) and is an extremely slow growing function.  log*(n) is defined as follows:  0, if n <= 1  1 + log*(log n) if n > 1 Algorithms Greedy Algorithms 19 UNION FIND – PATH COMPRESSION
  • 20.  Using 2 Find operations to check if adding an edge will create a cycle or not.  When adding an edge, use a Union Operation Algorithms Greedy Algorithms 20 TIME COMPLEXITY ANALYSIS OF KRUSKAL’S ALGORITHM
  • 21.  Proof by contradiction Algorithms Greedy Algorithms 21 WHY DOES KRUSKAL’S ALGORITHM WORK?
  • 22.  Optimal Substructure Property: A problem has optimal substructure if an optimal solution to the problem contains within it optimal solutions to its sub problems.  Greedy Choice Property: If a local greedy choice is made, then an optimal solution including this choice is possible. Algorithms Greedy Algorithms 22 TWO BASIC PROPERTIES OF OPTIMAL GREEDY ALGORITHMS
  • 23.  A subset system is a set E together with a set of subsets of E, called I, such that I is closed under inclusion. This means that if X ⊆ Y and Y ∈ I, then X ∈ I. (I is sometimes referred to as set of independent sets.)  A subset system is a matroid if it satisfies the exchange property: If i1 and i2 are sets in I and i1 has fewer elements than i2, then there exists an element e ∈ i2 i1 such that i1 ∪ {e} ∈ I.  For any subset system (E,I), the greedy algorithm solves the optimization problem for (E,I) if and only if (E,I) is a matroid. Algorithms Greedy Algorithms 23 GREEDY ALGORITHMS AND MATROIDS
  • 24.  Prone to overuse  You shouldn’t use this algorithm unless you can prove that the solution is optimal.  That is, no points in MT/Final for using greedy algorithm to produce a suboptimal solution, where another algorithmic technique (such as D&C) would have resulted in an optimal solution.  Why?  Optimality has a “business value”. Suppose you are trying to maximize the flights that you can schedule using 3 aircrafts.  Time complexity merely represents a “cost of computation” of that schedule.  If one algorithm runs in 1 minute, but schedules only 7 flights, and another algorithm runs in 2 hours, but schedules 8 flights, which one would you use? Algorithms Greedy Algorithms 24 WHEN NOT TO USE GREEDY ALGORITHM
  • 25.  Chess  Sorting  Shortest path computation  Knapsack Algorithms Greedy Algorithms 25 GREEDY: TO APPLY OR NOT TO APPLY
  • 27.  Greedy  Book – first problem on interval scheduling classes  http://en.wikipedia.org/wiki/Huffman_coding  http://www.cs.kent.edu/~dragan/AdvAlg05/GreedyAlg-1x1.pdf  Dynamic Programming  Dynamic Programming: Book sections 6.1 – 6.4  http://www.yaroslavvb.com/papers/wagner-dynamic.pdf Algorithms Greedy Algorithms 27 READING ASSIGNMENT Application # 5