Download presentation
Presentation is loading. Please wait.
1
UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 1 (Part 3) Tuesday, 9/4/01 Greedy Algorithms
2
What is a Greedy Algorithm? ä Solves an optimization problem ä Greedy Strategy: ä At each decision point, do what looks best “locally” ä Choice does not depend on evaluating potential future choices or solving subproblems ä Top-down algorithmic structure ä With each step, reduce problem to a smaller problem ä Greedy Choice Property: ä “locally best” = globally best ä Optimal Substructure: ä optimal solution contains in it optimal solutions to subproblems
3
Examples ä From 91.404 ä Minimum Spanning Tree ä Dijkstra’s single-source shortest path ä Huffman Codes ä Fractional Knapsack ä Activity Selection
4
Examples: Activity Selection ä Problem Instance: ä Set S = {1,2,...,n} of n activities ä Each activity i has: ä start time: s i ä finish time : f i ä Activities i, j are compatible iff non-overlapping: ä Objective: ä select a maximum-sized set of mutually compatible activities
6
Examples: Activity Selection ä Algorithm: ä S’ = presort activities in S by nondecreasing finish time ä and renumber ä GREEDY-ACTIVITY-SELECTOR(S’) ä n length[S’] ä A {1} ä j1 ä for i 2 to n ä do if ä then ä j i ä return A Running time?
7
Examples: Activity Selection ä Correctness: Board Work
8
Examples: Activity Selection ä Correctness: Board Work
9
Another use for Greedy Algorithm ä If optimization problem does not have “greedy choice property”, greedy algorithm may still be useful in bounding the optimal solution ä Example: minimization problem Optimal (unknown value) Upper Bound (heuristic) Lower Bound Solution Values
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.