Greed is Good But gluttony is a deadly sin
What are greedy algorithms? Why they are useful Dangers of using greedy algorithms
Prim’s Algorithm
a dc b
1 2 3 a dc b Minimum Spanning Tree
bc adf e PQ: (a,b,3) ; (a,f,5) ; (a,e,6)
bc adf e PQ: (b,c,1) ; (b,f,4) ; (a,f,5) ; (a,e,6)
bc adf e PQ: (c,f,4) ; (b,f,4) ; (a,f,5) ; (a,e,6) ; (c,d,6)
bc adf e PQ: (f,e,2) ; (b,f,4) ; (a,f,5) ; (f,d,5) ; (a,e,6) ; (c,d,6)
bc adf e PQ: (b,f,4) ; (a,f,5) ; (f,d,5) ; (a,e,6) ; (c,d,6) ; (e,d,8)
bc adf e
Kruskal’s Algorithm
bc adf e Sorted list: (b,c,1) ; (e,f,2) ; (a,b,3) ; (c,f,4) ; (b,f,4) ; (a,f,5) ; (d,f,5) ; (a,e,6) ; (c,d,6) ; (d,e,8)
bc adf e
bc adf e
bc adf e
bc adf e
bc adf e
DONE!! DANKEI THAKN YOU! Nou kan jy aangaan met jou lewe…