1 / 97

Greedy Algorithms: Introduction

Greedy Algorithms: Introduction. http://iti.wtf Algorithms and Data Structures. Artem A. Golubnichiy artem@golubnichij.ru Department of Software of Computer Facilities and Automated Systems Katanov Khakass State University. STRUCTURE OF THE CLASS. Maximize Your Salary

garyk
Télécharger la présentation

Greedy Algorithms: Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Greedy Algorithms:Introduction http://iti.wtf Algorithms and Data Structures Artem A. Golubnichiy artem@golubnichij.ru Department of Software of Computer Facilities and Automated Systems KatanovKhakass State University

  2. STRUCTURE OF THE CLASS • Maximize Your Salary • Queue of Patients • Implementation and Analysis • Main Ingredients

  3. WHAT’S COMING • Solve salary maximization problem • Come up with a greedy algorithm yourself • Solve optimal queue arrangement problem • Generalize solutions using the concepts of greedy choice, subproblem and safe choice

  4. MAXIMIZE SALARY

  5. MAXIMIZE SALARY

  6. MAXIMIZE SALARY

  7. LARGEST NUMBER

  8. LARGEST NUMBER

  9. LARGEST NUMBER

  10. GREEDY STRATEGY {9, 8, 9, 6, 1} → ?????

  11. GREEDY STRATEGY Find max {9, 8, 9, 6, 1} Find max digit

  12. GREEDY STRATEGY Find max {9, 8, 9, 6, 1} Find maxdigit

  13. GREEDY STRATEGY Find max Append {9, 8, 9, 6, 1} → Find maxdigit Append it to the number

  14. GREEDY STRATEGY Find max Append {9, 8, 9, 6, 1} → 9 Find maxdigit Append it to the number

  15. GREEDY STRATEGY Find max Append {9, 8, 9, 6, 1} → 9 Remove Find maxdigit Append it to the number Remove it from the list of digits

  16. GREEDY STRATEGY Find max Append {9, 8, 9, 6, 1} → 9 Remove Find maxdigit Append it to the number Remove it from the list of digits

  17. GREEDY STRATEGY Find max Append {8, 9, 6, 1} → 9 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  18. GREEDY STRATEGY Find max Append {8, 9, 6, 1} → 9 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  19. GREEDY STRATEGY Find max Append {8, 9, 6, 1} → 99 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  20. GREEDY STRATEGY Find max Append {8, 9, 6, 1} → 99 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  21. GREEDY STRATEGY Find max Append {8, 6, 1} → 99 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  22. GREEDY STRATEGY Find max Append {8, 6, 1} → 99 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  23. GREEDY STRATEGY Find max Append {8, 6, 1} → 998 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  24. GREEDY STRATEGY Find max Append {8, 6, 1} → 998 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  25. GREEDY STRATEGY Find max Append {6, 1} → 998 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  26. GREEDY STRATEGY Find max Append {6, 1} → 998 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  27. GREEDY STRATEGY Find max Append {6, 1} → 9986 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  28. GREEDY STRATEGY Find max Append {6, 1} → 9986 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  29. GREEDY STRATEGY Find max Append {1} → 9986 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  30. GREEDY STRATEGY Find max Append {1} → 9986 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  31. GREEDY STRATEGY Find max Append {1} → 99861 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  32. GREEDY STRATEGY Find max Append {1} → 99861 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  33. GREEDY STRATEGY Find max Append {} → 99861 Remove Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  34. GREEDY STRATEGY Find max Append {9, 8, 9, 6, 1} → 99861 Remove Success! Find maxdigit Append it to the number Remove it from the list of digits Repeat while there are digits in the list

  35. QUEUE OF PATIENTS

  36. QUEUE OF PATIENTS

  37. QUEUE OF PATIENTS

  38. QUEUE OF PATIENTS

  39. QUEUE OF PATIENTS

  40. QUEUE OF PATIENTS

  41. QUEUE OF PATIENTS

  42. QUEUE OF PATIENTS

  43. QUEUE OF PATIENTS

  44. QUEUE OF PATIENTS

  45. GREEDY STRATEGY • Make some greedy choice • Reduce to a smaller problem • Iterate

  46. GREEDY CHOICE • First treat the patient with the maximum treatment time • First treat the patient with the minimum treatment time • First treat the patient with average treatment time

  47. GREEDY ALGORITHM • First treat the patient with the minimum treatment time

  48. GREEDY ALGORITHM • First treat the patient with the minimum treatment time • Remove this patient from the queue

  49. GREEDY ALGORITHM • First treat the patient with the minimum treatment time • Remove this patient from the queue • Treat all the remaining patients in such order as to minimize their total waiting time

  50. SUBPROBLEM

More Related