Lecture 7 - The Greedy Approach

Lecture 7 - The Greedy Approach - The Greedy Approach The...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
The Greedy Approach
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Greedy Approach Like Dynamic Programming, greedy algorithms are often used to solve optimization problems. In the greedy approach there is no division of the problem into smaller instances. No need for a recursive property The greedy algorithm arrives at the solution by making a sequence of choices: – Each choice made looks best in the local current context: locally optimal . – Does not take into consideration previous or future choices. By making locally optimal solution the greedy algorithm may fail to produce a globally optimal solution. For a given algorithm we must determine whether the solution is always optimal.
Background image of page 2
The Greedy Approach: How it Works ? 1. Select largest coin in value : Selection Procedure 2. Is it OK to add coin to selection set ? (does not exceed $0.83) Feasibility Check 3. Check if total value of selected coins equals value to return. Solution Check Problem : Return change of $0.83. Set representing the solution to the problem Available coins Selection criteria
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Greedy Approach and Optimality Problem : Return change of $0.82. If a solution exist, does the greedy algorithm always return an optimal Solution ? Available coins Set representing the solution to the Pb using Greedy Algo. Optimal Solution A Greedy Algorithm does not guarantee an Optimal solution
Background image of page 4
A greedy algorithm starts with an empty set and add items to the set in sequence until the set represents a solution to an instance of the problem. Thus, the greedy approach consists of an iteration of the following computations: - Selection procedure - a selection procedure is created to choose the next item to add to a list of locally optimal solutions to subproblems. - Feasibility check - a test is made to see if the current set of choices satisfies some locally optimal criterion. - Solution check - when a complete set is obtained it is checked to verify that it constitutes a solution for the original problem. The Greedy Approach: General Outline
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Minimum Spanning Trees v 1 2 3 4 5 2 4 3 3 5 1 6 1 2 3 4 3 5 1 6 1 2 3 4 2 4 3 1 A Spanning Tree A minimum Spanning Tree Undirected Graph An undirected graph is connected if there is a Path between every pair of vertices. A Tree is an acyclic, connected, undirected graph: Exactly one path between every pair of vertices A Spanning Tree for a graph G is a connected subgraph that contains all the vertices in G and is a tree: A set of |V| - 1 edges that connect all vertices in G. A Minimum Spanning Tree for a graph G is a spanning tree for G That has a minimum total weight. An undirected graph G consists of a finite set of vertices V and a set E of pair of vertices in V called edges of G. G is denoted by: G = (V, E)
Background image of page 6
Greedy Algorithm for MST: Prim’s Algo. -I- Prim’s Algorithm: – Start at a vertex v with an empty set of edges F. – Add to the set F the cheapest edge adjacent to v
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/14/2011 for the course CMPS 323 taught by Professor Shaban during the Spring '11 term at Qatar University.

Page1 / 30

Lecture 7 - The Greedy Approach - The Greedy Approach The...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online