Anda di halaman 1dari 18

MODULE III

Greedy Method Dynamic Programming


Anna Maria Varghese Aneena Mathew Fajar P.M. Hegel J. Meenu Thankachan Tanya Ann Joseph

Greedy method
Applies to optimization problems in which certain choices are available to reach at the solution Works in stages by considering one input at a time A greedy choice must be Feasible Locally optimal Irrevocable

Greedy method - problems


Knapsack problem Job sequencing with deadline Minimum cost spanning tree Prims Algorithm Kruskals Algorithm Optimal storage on tapes

Knapsack problem Given n objects and a sack to maximize profit by filling the knapsack 0-1 knapsack Fractional knapsack Job sequencing with deadline A set of n jobs with deadlines di, profits pi where the feasible solution is a subset j of jobs such that each job can be finished by its deadline

Minimum cost spanning tree Finds the spanning tree with the minimum cost using any of the two algorithmsPrims or Kruskals algorithm Optimal storage on tapes n programs with length li to be stored on a computer tape. All programs can be stored if and only if the sum of the length of programs is almost l

Dynamic programming
Solves problem by dividing into several dependent sub problems Combines the sub problems solutions Sub problems share sub sub problems

Dynamic programming - problems


Multistage graphs All pairs shortest path Floyd Warshall Algorithm Johnsons Algorithm The travelling salesman problem

Multistage graphs Problem is to find the minimum cost path from source vertex to end vertex All pairs shortest path problem Finds the shortest path between all pairs of vertices in graph G= <V,E> Floyd Warshall Algorithm Johnsons Algorithm

Travelling salesman problem Problem is to visit different cities and finally reach same city from where he started with an optimal path

KNAPSACK PROBLEM

One- dimensional knapsack

KNAPSACK PROBLEM
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.

KNAPSACK PROBLEM-APPLICATIONS
Knapsack problems appear in real-world decision-making processes in a wide variety of fields, such as: Finding the least wasteful way to cut raw materials. Selection of capital investments. Financial portfolios. Selection of assets for asset-backed securitization. Generating keys for the MerkleHellman knapsack cryptosystem.

PROBLEM DEFINITION
The problem can be stated as maximize pixi Subject to wixi<=m where 1<=i<=n And 0<=xi<=1 , 1<=i<=n A feasible solution or filling is any set (x1.xn) satisfying the above equations An optimal solution is a feasible solution for which the profit is maximized

COMPLEXITY
The knapsack algorithm takes O(nlogn) time if arranging profits array uses either merge sort or heap sort; otherwise only O(n) time will be required.

EXAMPLE PROBLEM
Find an optimal solution to the knapsack instance: n=7,W=15, (v1,v2,v3,v4,v5,v6,v7)=(10,5,15,7,6,18,3) and (w1,w2,w3,w4,w5,w6,w7)=(2,3,5,7,1,4,1).

Kruskals Algorithm
1. Start with names of the edges being part of the solution. 2. Then add edges one at a time, starting with the lowest weighted edge. But dont add all edge if it would create a circuit. 3. Keep adding edges until every vertex is connected to the network.

THANK YOU

Anda mungkin juga menyukai