Unit-2-Matroids & GraphMatching (3)
Unit-2-Matroids & GraphMatching (3)
Greedy Paradigm
• Greedy approaches are applicable to optimization problems
• An optimization problem is the problem of finding the best solution from all
feasible solutions
• An optimization problem is associated with an objective function and a set of
constraints. The solution to a problem is to create a subset of solutions that
satisfies constraints associated with the problem.
• Any subset solution that satisfies constraints is called a feasible solution
• Any feasible solution that maximizes or minimizes the given objective function
is called the optimal solution
Examples:
• Finding the shortest path : we wish to find the path with lowest weight
• Making coin change
• Storing files in a compressed form in a disk
• Optimally loading a suitcase with items of different weights
• Optimally arranging a shelf
Greedy Paradigm
• The greedy approach works in stages.
• At every stage, a decision or choice is made
• These decisions are locally optimal
• Finally, the global solution of the problem is
obtained by combining locally optimal
decisions.
Greedy Paradigm
• A greedy algorithm always makes the choice
that looks best at the moment.
• it makes a locally optimal choice in the hope
that this choice will lead to a globally optimal
solution
• The greedy method is quite powerful and
works well for a wide range of problems.
Comnponents of greedy algorithm
• Objective function
• Generating multiple candidate solutions
• Selection procedure
• Feasibility check
• Solution check
Greedy Paradigm
Applications of the greedy method, including
• minimum-spanning-tree algorithms
• Dijkstra’s algorithm for shortest paths from a
single source ,
• Chv´atal’s greedy set-covering heuristic
Algorithm greedy(A,n)
Input: Array a[1…n]
Output: solution of the problem
SolutionSet=Null
while(Solution is not complete) do
Select a best candidate solution x
If x is a feasible solution then
Add the solution x to the Solutionset
end if
%%Check if the solution of the given problem is obtained
If(solution obtained) then
return Solutionset
end if
end while
end
Important properties of a greedy algorithm
• Optimum substructure
A problem has an optimal substructure if an
optimal solution to the entire problem contains
the optimal solutions to the sub-problems
• Greedy Choice property
A global (overall) optimal solution can be reached
by choosing the optimal choice at each step
An Activity Selection Problem
• The problem is to schedule several competing activities that require exclusive use of a
common resource, with a goal of selecting a maximum-size set of mutually compatible
activities.
• Suppose we have a set of n proposed activities that wish to use a
resource, such as a lecture hall, which can serve only one activity at a time.
• Each activity has a start time and a finish time , where
• If selected, activity takes place during the half-open time interval
• Assume the activities are sorted in monotonically increasing order of finish time:
Greedy Paradigm
• An algorithm to solve the activity-selection problem does
not need to work bottom-up, like a table-based dynamic-
programming algorithm.
• It works top-down, choosing an activity to put into the
optimal solution and then solving the sub problem of
choosing activities from those that are compatible with
those already chosen.
• Greedy algorithms typically have this top-down design:
make a choice and then solve a sub problem, rather than
the bottom-up technique of solving subproblems before
making a choice
The Activity Selection Problem
A recursive greedy algorithm
• Thus, the value per pound of item 1 is 6 dollars per pound, which is
greater than the value per pound of either item 2 (5 dollars per pound)
or item 3 (4 dollars per pound)
• In a graphic matroid , If A is an
independent set of edges, then edge e is an
extension of A if and only if e is not in A (
) and the addition of e to A does not create a
cycle
Maximal Independent Set
• If A is an independent subset in a matroid M,
A is said to be maximal if it has no extensions.
That is, A is maximal if it is not contained in
any larger independent subset of M.
• All maximal independent subsets in a matroid
have the same size
Spanning Tree
• is a graphic matroid for a connected, undirected graph
G,
• Every maximal independent subset of must be a free
tree with exactly |V |-1 edges that connects all the vertices
of G
• Such a tree is called a spanning tree of G
• A matroid M =(S,I) is weighted if it is associated with a
weight function w that assigns a strictly positive weight
w(x) to each element
• The weight function w extends to subsets of S by
summation:
For example, if w(e) denote the weight of an edge e in a graphic matroid , then
w(A) is the total weight of the edges in edge set A
Greedy algorithms on a weighted matroid