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

Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 
Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmIfad Rahman
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Computational Complexity: Complexity Classes
Computational Complexity: Complexity ClassesComputational Complexity: Complexity Classes
Computational Complexity: Complexity ClassesAntonis Antonopoulos
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 

What's hot (20)

Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's Algorithm
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Computational Complexity: Complexity Classes
Computational Complexity: Complexity ClassesComputational Complexity: Complexity Classes
Computational Complexity: Complexity Classes
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 

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
 
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
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 

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
 
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
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 

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
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder 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
 

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
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
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
 

Recently uploaded

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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
 
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
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
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...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
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...
 
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
 

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