Docsity

Greedy Algorithm-Algorithm Fundamentals-Assignment Solution, Exercises of Algorithms and Programming

Toggle sidebar
bg1
CS 502 Fundamental of Algorithms
Assignment # 03
Spring 2012 Total Marks = 20
Deadline
Your assignment must be uploaded / submitted before or on June 11, 2012
Upload Instructions
Please view the assignment submission process document provided to you by the
Virtual University.
Rules for Marking
Please note that your assignment will not be graded if:
• It is submitted after due date
• The file you uploaded does not open
• The file you uploaded is copied from someone else or from internet
• It is in some format other than .doc
Note: Material that is an exact copy from handouts or internet would be graded
Zero marks. Your solution should consist of the material found through
different sources and written in your own words.
Assignment Statements:
Question:
Suppose that instead of always selecting the first activity to finish,
we instead select the last activity to start that is compatible with all
previously selected activities. Describe how this approach is a
greedy algorithm, and prove that it yields an optimal solution.
Solution:
The proposed approach: selecting the last activity to start that is
compatible with all previously selected activities: is really the greedy
algorithm but starting from the end rather than the beginning.
Another way to look at it is as follows. We are given a set S = {a1, a2. . .
an} of activities, where ai = [si , fi] , and we propose to find an optimal
solution by selecting the last activity to start that is compatible with all
previously selected activities. Instead, let us create a set Sˊ = {aˊ1, aˊ2. .
.aˊn}, where aˊi= [ fi , si]. That is, aˊi is ai in reverse. Clearly, a subset of
{ai1, ai2. . . aik} ⊆ S is mutually compatible if and only if the
docsity.com
pf2

Partial preview of the text

Download Greedy Algorithm-Algorithm Fundamentals-Assignment Solution and more Exercises Algorithms and Programming in PDF only on Docsity!

CS 502 Fundamental of Algorithms

Assignment # 03

Spring 2012

Total Marks = 20

Deadline

Your assignment must be uploaded / submitted before or on June 11, 2012

Upload Instructions

Please view the assignment submission process document provided to you by the Virtual University.

Rules for Marking

Please note that your assignment will not be graded if:

  • It is submitted after due date
  • The file you uploaded does not open
  • The file you uploaded is copied from someone else or from internet
  • It is in some format other than .doc

Note: Material that is an exact copy from handouts or internet would be graded Zero marks. Your solution should consist of the material found through different sources and written in your own words.

Assignment Statements:

Question:

Suppose that instead of always selecting the first activity to finish, we instead select the last activity to start that is compatible with all previously selected activities. Describe how this approach is a greedy algorithm, and prove that it yields an optimal solution.

Solution:

The proposed approach: selecting the last activity to start that is compatible with all previously selected activities: is really the greedy algorithm but starting from the end rather than the beginning.

Another way to look at it is as follows. We are given a set S = { a 1 , a 2_... an_ } of activities, where ai = [ si , fi ] , and we propose to find an optimal solution by selecting the last activity to start that is compatible with all previously selected activities. Instead, let us create a set Sˊ = { aˊ 1 , aˊ 2_.. .aˊn_ }, where aˊi = [ fi , si ]. That is, aˊi is ai in reverse. Clearly, a subset of { ai 1 , ai 2_... aik_ } ⊆ S is mutually compatible if and only if the

docsity.com

corresponding subset { aˊi 1 , aˊi 2 ,... , aˊik } ⊆ Sˊ is also mutually compatible. Thus, an optimal solution for S maps directly to an optimal solution for Sˊ and vice versa.

The proposed approach of selecting the last activity to start that is compatible with all previously selected activities, when run on S , gives the same answer as the greedy algorithm from the text-selecting the first activity to finish that is compatible with all previously selected activities- when run on Sˊ. The solution that the proposed approach finds for S corresponds to the solution that the text’s greedy algorithm finds for Sˊ , and so it is optimal.

docsity.com