12 a algorithm design techniques ii
play

12 A: Algorithm Design Techniques II CS1102S: Data Structures and - PowerPoint PPT Presentation

Greedy Algorithms (brief review) Divide and Conquer (Example) Dynamic Programming Backtracking Algorithms Another Puzzler 12 A: Algorithm Design Techniques II CS1102S: Data Structures and Algorithms Martin Henz April 7, 2010 Generated on


  1. Greedy Algorithms (brief review) Divide and Conquer (Example) Dynamic Programming Backtracking Algorithms Another Puzzler 12 A: Algorithm Design Techniques II CS1102S: Data Structures and Algorithms Martin Henz April 7, 2010 Generated on Tuesday 6 th April, 2010, 14:42 CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 1

  2. Greedy Algorithms (brief review) Divide and Conquer (Example) Dynamic Programming Backtracking Algorithms Another Puzzler 1 Greedy Algorithms (brief review) 2 Divide and Conquer (Example) 3 Dynamic Programming 4 Backtracking Algorithms 5 Another Puzzler CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 2

  3. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler 1 Greedy Algorithms (brief review) Scheduling Huffman Codes 2 Divide and Conquer (Example) 3 Dynamic Programming 4 Backtracking Algorithms 5 Another Puzzler CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 3

  4. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Nonpreemptive Scheduling Input A set of jobs with a running time for each CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 4

  5. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Nonpreemptive Scheduling Input A set of jobs with a running time for each Desired output A sequence for the jobs to execute on on single machine, minimizing the average completion time CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 5

  6. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Example Some schedule: The optimal schedule: CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 6

  7. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler The Multiprocessor Case N processors Now we can run the jobs on N identical machines. What is a schedule that minimizes the average completion time? CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 7

  8. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 8

  9. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler A “Slight” Variant Miniming final completion time If we want to minimize the final completion time (completion time of the last task), the problem becomes NP-complete! CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 9

  10. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Optimal Prefix Code in Table Form CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 10

  11. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Optimal Prefix Code in Tree Form CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 11

  12. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 12

  13. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 13

  14. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 14

  15. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 15

  16. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 16

  17. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 17

  18. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Huffman’s Algorithm: An Example CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 18

  19. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 1 An optimal tree must be full; no node has only one child. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 19

  20. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 1 An optimal tree must be full; no node has only one child. Observation 2 The two least frequent characters α and β must be the two deepest nodes. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 20

  21. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 1 An optimal tree must be full; no node has only one child. Observation 2 The two least frequent characters α and β must be the two deepest nodes. Observation 3 Characters at the same level can be swapped without affecting optimality. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 21

  22. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 3 Characters at the same level can be swapped without affecting optimality. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 22

  23. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 3 Characters at the same level can be swapped without affecting optimality. Initial Step of Huffman’s Algorithm An optimal tree can be found that contains the two least frequent symbols as siblings; the first step in Huffman’s algorithm is not a mistake. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 23

  24. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 3 Characters at the same level can be swapped without affecting optimality. Initial Step of Huffman’s Algorithm An optimal tree can be found that contains the two least frequent symbols as siblings; the first step in Huffman’s algorithm is not a mistake. Observation 4 Every step of Huffman’s algorithm produces a simplified problem, resulting from treating two characters as indistinguishable. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 24

  25. Greedy Algorithms (brief review) Divide and Conquer (Example) Scheduling Dynamic Programming Huffman Codes Backtracking Algorithms Another Puzzler Correctness of Huffman’s Algorithm Observation 3 Characters at the same level can be swapped without affecting optimality. Initial Step of Huffman’s Algorithm An optimal tree can be found that contains the two least frequent symbols as siblings; the first step in Huffman’s algorithm is not a mistake. Observation 4 Every step of Huffman’s algorithm produces a simplified problem, resulting from treating two characters as indistinguishable. CS1102S: Data Structures and Algorithms 12 A: Algorithm Design Techniques II 25 Each Step of Huffman’s Algorithm

Recommend


More recommend