Chapter 3 : Greedy Method
Content to be cover.
• Introduction to Greedy method
• Optimal Merge Pattern & Huffman Coding
• Kanpsack Problem
• Activity Selection Problem
• Job sequencing with deadlines
• Minimum Spanning Tree
• Single-Source Shortest Path
Content Covered : Introduction
Introduction
• Simple & Straight forward method used to solve optimization problem.
• Feasible solution
• Optimal Solution
Control Abstraction for Greedy Method :
• Select (x) :
• It is a function that selects optimal x from the input set C.
• Feasible (S  {x}) :
• It is a function that checks if S  x is a feasible solution.
• Solution (S) :
• It is a function that returns true then solution is found.
Chapter 3 : Greedy Method
Chapter 3 : Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
Optimal Merge Pattern : It is the way in which many files (presently two at a time) can be merged optimally.
Consider the following files F1, F2, F3 contains 100, 110, 90 records respectively.
Suppose F1 and F2 are merged first to get file ‘T1’ then records movements will be 100 + 110 = 210.
If F3 is merged with ‘T1’ then records movement will be 210 + 90 = 300.
 Total record movements = 210 + 300 = 510
Suppose if the files F2 and F3 are merged first to get file ‘T1’ then records movements will be 110 + 90 = 200.
If F1 is merged with ‘T1’ then records movement will be 200 + 100 = 300.
 Total record movements = 200 + 300 = 500
Suppose if the files F1 and F3 are merged first to get file ‘T1’ then records movements will be 100 + 90 = 190.
If F2 is merged with ‘T1’ then records movement will be 190 + 110 = 300.
 Total record movements = 190 + 300 = 490
From above example it can be seen that by changing the merge pattern it is possible to get minimum records movements.
Feasible solution : Every merging operation is a feasible solution.
Optimal solution : It is a feasible solution with least record movements.
Chapter 3 : Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
Chapter 3 : Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
Chapter 3 : Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
Solve the following example
Example 1 : Find optimal merge pattern for ten files whose lengths are Also Find the Overall record
movements.
26, 32, 12, 6, 85, 55, 90, 35, 3 and 11.
Example 2 : Find optimal merge pattern for Seven files whose lengths are Also Find the Overall record
movements.
4, 5, 7, 8, 10, 12, 20

Chapter 3 greedy method lecture 1

  • 1.
    Chapter 3 :Greedy Method Content to be cover. • Introduction to Greedy method • Optimal Merge Pattern & Huffman Coding • Kanpsack Problem • Activity Selection Problem • Job sequencing with deadlines • Minimum Spanning Tree • Single-Source Shortest Path
  • 2.
    Content Covered :Introduction Introduction • Simple & Straight forward method used to solve optimization problem. • Feasible solution • Optimal Solution Control Abstraction for Greedy Method : • Select (x) : • It is a function that selects optimal x from the input set C. • Feasible (S  {x}) : • It is a function that checks if S  x is a feasible solution. • Solution (S) : • It is a function that returns true then solution is found. Chapter 3 : Greedy Method
  • 3.
    Chapter 3 :Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding Optimal Merge Pattern : It is the way in which many files (presently two at a time) can be merged optimally. Consider the following files F1, F2, F3 contains 100, 110, 90 records respectively. Suppose F1 and F2 are merged first to get file ‘T1’ then records movements will be 100 + 110 = 210. If F3 is merged with ‘T1’ then records movement will be 210 + 90 = 300.  Total record movements = 210 + 300 = 510 Suppose if the files F2 and F3 are merged first to get file ‘T1’ then records movements will be 110 + 90 = 200. If F1 is merged with ‘T1’ then records movement will be 200 + 100 = 300.  Total record movements = 200 + 300 = 500 Suppose if the files F1 and F3 are merged first to get file ‘T1’ then records movements will be 100 + 90 = 190. If F2 is merged with ‘T1’ then records movement will be 190 + 110 = 300.  Total record movements = 190 + 300 = 490 From above example it can be seen that by changing the merge pattern it is possible to get minimum records movements. Feasible solution : Every merging operation is a feasible solution. Optimal solution : It is a feasible solution with least record movements.
  • 4.
    Chapter 3 :Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
  • 5.
    Chapter 3 :Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding
  • 6.
    Chapter 3 :Greedy Method Content Covered : Optimal Merge Pattern & Huffman coding Solve the following example Example 1 : Find optimal merge pattern for ten files whose lengths are Also Find the Overall record movements. 26, 32, 12, 6, 85, 55, 90, 35, 3 and 11. Example 2 : Find optimal merge pattern for Seven files whose lengths are Also Find the Overall record movements. 4, 5, 7, 8, 10, 12, 20