Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(10) The greedy algorithm for the activity selection problem we discussed (Rosen

ID: 3604090 • Letter: #

Question

(10) The greedy algorithm for the activity selection problem we discussed (Rosen pp. 417-421) can be stated as "Always select the activity having the earliest finish time, discard the activities incompatible with the selection just made, and work on the resulting subproblem." Show that the following greedy strategies (that replaces the underlined part) do not always yield an optimal solution for the activity selection problem, by giving a counterexample for each

Explanation / Answer

sing System; using System.Linq; using System.IO; class Program { static void Main(string[] args) { string[] dirfiles = Directory.GetFiles("c:\sri\"); var avg = dirfiles.Select(file =>new FileInfo(file).Length).Average(); avg = Math.Round(avg / 10, 1); Console.WriteLine("The Average file size is {0} MB",avg); Console.ReadLine(); } }