UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Lecture 2 Tuesday, 9/10/02 Design Patterns for Optimization Problems Greedy Algorithms
Algorithmic Paradigm Context
Greedy Algorithms
What is a Greedy Algorithm? ä Solves an optimization problem ä Optimal Substructure: ä optimal solution contains in it optimal solutions to subproblems ä 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
Examples ä Minimum Spanning Tree ä Dijkstra Shortest Path ä Huffman Codes ä Fractional Knapsack ä Activity Selection
Minimum Spanning Tree
A B C D E F G source: textbook Cormen et al. for Undirected, Connected, Weighted Graph G=(V,E) Produces minimum weight tree of edges that includes every vertex. Invariant: Minimum weight spanning forest Becomes single tree at end Invariant: Minimum weight tree Spans all vertices at end Time: O(|E|lg|E|) given fast FIND-SET, UNION Time: O(|E|lg|V|) = O(|E|lg|E|) slightly faster with fast priority queue
Dijkstra Shortest Path
Single Source Shortest Paths: Dijkstra’s Algorithm source: textbook Cormen et al. for (nonnegative) weighted, directed graph G=(V,E) A B C D E F G
Huffman Codes
Fractional Knapsack
item1item2item3 “knapsack” Value: $60 $100$120
Activity Selection
Example Optimization Problem: 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 source: textbook Cormen, et al.
Algorithmic Progression ä “Brute-Force” ä (board work) ä Dynamic Programming #1 ä Exponential number of subproblems ä (board work) ä Dynamic Programming #2 ä Quadratic number of subproblems ä (board work) ä Greedy Algorithm ä (board work)
Running time? Greedy Algorithm ä 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 source: textbook Cormen, et al.
Additional Examples On course web site under Miscellaneous Docs ä Patriotic Tree ä 404 review handout ä Tree Vertex Cover ä midterm
Greedy Heuristic ä If optimization problem does not have “greedy choice property”, greedy approach may still be useful as a heuristic in bounding the optimal solution ä Example: minimization problem Optimal (unknown value) Upper Bound (heuristic) Lower Bound Solution Values
New Research in Dynamic Channel Assignment [GLOBECOM 2001, IEEE VT submission] ä Input: ä Number of time periods ä 7 x 7 square cell grid ä Set of channels ä Co-channel interference threshold B = ä Demand for each time period ä Output: ä For each time period ä Feasible assignment of channels to cells satisfying: ä Demand model ä Co-channel interference constraints ä (SignalStrength/Interference) > B ä Computation time limit ä Minimize number of channels used ä Minimize reassignments across time solution assumes no channel repetition within any 2 x 2 square Sample solution for 1 time period Demand Assignment 5 different channels are used Joint work with Prof. Chandra, graduate students S. Liu, S.Widhani
Homework 1 T 9/3 T 9/ review & Chapter 15 2 T 9/10 T 9/17 Chapter 16 HW# Assigned Due Content