/
“Classic” Examples of Greedy Algorithms “Classic” Examples of Greedy Algorithms

“Classic” Examples of Greedy Algorithms - PowerPoint Presentation

ella
ella . @ella
Follow
345 views
Uploaded On 2022-06-18

“Classic” Examples of Greedy Algorithms - PPT Presentation

Minimum spanning tree MST Single source shortest path SSSP eg Dijkstras algorithm We will explore the main properties with focus on theoretical foundations MST Graph GVE undirected connected weighted arbitrary real weights w on edges ID: 920203

cut mst safe edge mst cut edge safe tree edges algorithm spanning generic light time acyclic greedy graph find

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "“Classic” Examples of Greedy Algorit..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

“Classic” Examples of Greedy Algorithms

Minimum spanning tree (MST)

Single source shortest path (SSSP), e.g., Dijkstra’s algorithm

We will explore the main properties, with focus on theoretical foundations

Slide2

MST:

Graph G(V,E): undirected, connected, weighted (arbitrary real weights w() on edges)

Goal: find acyclic subset

E of edges (acyclic subgraph of G) that:Connects all vertices in V (spanning V; acyclic property implies it is a tree) is minimizedT acyclic, connects all vertices  T is a spanning tree of G, of minimum weight  minimum spanning treeWill discuss two greedy strategies to find MSTIn general, MST for a graph G is not unique

 

Slide3

Two greedy algorithms

We will “abuse” notation so V also denotes the

number

of vertices and E also denotes the number of edges (instead of using |V| and |E|)Kruskal’s algorithm: O(E log(V)) time, usesSortingDisjoint set operations (Union, Find)Prim’s algorithm:O(E log (V)) time with binary heap implementationO(E + V log(V)) time with Fibonacci heap implementationWill not discuss Fibonacci heaps in class – see the textbookFocus on theoretical aspects of the problem

Slide4

Generic MST algorithm

Grows a MST by adding one edge at a time

Captures the greedy strategy (edge added by greedy choice)

Invariant: The set A of added edges is always a subset of some MSTAt each step, finds edge (u,v) to add to ASuch edge (u,v) is called a safe edgeHas V-1 steps (a tree on V vertices has V-1 edges)We are not concerned with the running time of the generic algorithm

Slide5

Generic MST algorithm

Generic_MST

(

G,w)A  ⏀while A is not a spanning tree of G doFind edge (u,v) safe for AA  A {(u,v)}return ADifficulty: find a safe edgeone must exist sinceA T, for some MST TThus there exists (u,v) T, (u,v) A  (

u,v

) safe for A (by definition)

Need rule to

recognize

safe edges

 

Slide6

Definitions:

Cut

(S,V-S) of G(V,E): partition of V into two disjoint subsets

Edge (u,v) crosses the cut if u S, v V-S (or vice versa)Cut (S,V-S) respects A if no edge in A crosses the cut Edge (u,v) is called a light edge for a cut (S,V-S) if:(u,v) crosses the cutw(u,v) is the smallest among all edges crossing the cut: w(u,v) = min{w(x,y) | (x,y) edge crossing the cut}In general, given a cut, a light edge is not unique 

a

c

g

e

d

b

f

8

5

9

5

8

6

4

9

S

V-S

(

b,d

)

and

(

c,e

)

are light

G

Slide7

Theorem

Given graph G(V,E), let A be a subset of E included in some MST T of G

Let (S, V-S) be a cut of V that respects A (any such cut)

Let (u,v) be a light edge crossing the cut (S,V-S)Then (u,v) is safe for AProof:We know A T and (u,v) A. Then either (a) (u,v) T and we are done (by definition, (u,v) is safe for A) or (b) (u,v) T. Thus, assume (u,v) T. 

Slide8

Proof (cont.):

(

u,v

) TWe will construct another MST, T’, such that (A (u,v)) T’  (by definition) (u,v) is safe for A.Consider path P(u,v) in T, from u to v:(u,v) forms a cycle if added to P(u,v)u S, v V-S (x,y) P(u,v) that crosses cut (S,V-S) (x S, y

V-S)

Edge (

x,y

)

A, since cut (S,V-S) respects A

Removing (

x,y

) breaks T in two subtrees, adding (

u,v

) reconnects them into another (spanning) tree T’

w(

u,v

)

w(x,y) (both cross cut (S,V-S)), thus w(T’)

w(T) so T’ is a MST of G Remains to prove (u,v) is safe for A (w.r.t. T’)A T, (x,y)

A  A T’ (A (u,v))

T’ , T’ is a MST  (by definition) (u,v) is safe for A 

Slide9

Observations:

A is always acyclic

At any step of the generic MST algorithm, subgraph G

A(V,A) is a forest each connected component of GA is a treeAt first (A=⏀), GA has V components, each a 1-node treeA safe edge (u,v) connects two distinct components of GAThe loop of Generic_MST:executes V-1 times terminates when GA has one component (GA is a tree)

Slide10

Next: MST algorithms

MST algorithms use the following

Corollary

: Given G(V,E) let A be a subset of E included in some MST T of G.Let C be a connected component (tree) of the graph GA(V,A)Let (u,v) be a smallest weight edge connecting C to another component (tree) of GAThen, (u,v) is safe for AProof: (C,V-C) is a cut of G that respects A  (u,v) is a light edge for cut (C,V-C)  we have the setup of the Theorem  (u,v) is safe for A