Greed is Good But gluttony is a deadly sin - PowerPoint PPT Presentation

greed is good but gluttony is a deadly sin n.
Skip this Video
Loading SlideShow in 5 Seconds..
Greed is Good But gluttony is a deadly sin PowerPoint Presentation
Download Presentation
Greed is Good But gluttony is a deadly sin

play fullscreen
1 / 21
Download Presentation
136 Views
Download Presentation

Greed is Good But gluttony is a deadly sin

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Greed is GoodBut gluttony is a deadly sin

  2. What are greedy algorithms? • Why they are useful • Dangers of using greedy algorithms

  3. Prim’s Algorithm

  4. 1 a b 2 5 3 c d

  5. Minimum Spanning Tree 1 a b 2 3 c d


  6. 1 3 6 4 4 5 5 2 6 8 PQ: (a,b,3) ; (a,f,5) ; (a,e,6) b c a f d e

  7. 1 3 6 4 4 5 5 2 6 8 PQ: (b,c,1) ; (b,f,4) ; (a,f,5) ; (a,e,6) b c a f d e

  8. 1 3 6 4 4 5 5 2 6 8 PQ: (c,f,4) ; (b,f,4) ; (a,f,5) ; (a,e,6) ; (c,d,6) b c a f d e

  9. 6 4 4 5 5 2 6 8 PQ: (f,e,2) ; (b,f,4) ; (a,f,5) ; (f,d,5) ; (a,e,6) ; (c,d,6) 1 b c 3 a f d e

  10. 6 4 5 5 6 8 PQ: (b,f,4) ; (a,f,5) ; (f,d,5) ; (a,e,6) ; (c,d,6) ; (e,d,8) 1 b c 3 4 a f d 2 e

  11. 6 4 5 6 8 1 b c 3 4 5 a f d 2 e

  12. Kruskal’s Algorithm

  13. 1 3 6 4 4 5 5 2 6 8 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) b c a f d e

  14. 3 6 4 4 5 5 2 6 8 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) 1 b c a f d e

  15. 1 3 6 4 4 5 5 2 6 8 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) b c a f d e

  16. 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) 1 b c 3 6 4 4 5 5 a f d 2 6 8 e

  17. 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) 1 b c 3 6 4 4 5 5 a f d 2 6 8 e

  18. 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) 1 b c 3 6 4 4 5 5 a f d 2 6 8 e

  19. DONE!!DANKEITHAKN YOU! Nou kan jy aangaan met jou lewe…