Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Foundation of Algorithms

Assignment 5
Chinmay Kulkarni (ck1166)

2.

if we take z as source:

if we take s as source and change weight edge (z, x) to 4

-2

3. Suppose the activities are S<a1, a2, a3, a4. an > and there start time
finish time are given as follows ai = [ si , fi). Now, we want to start from last
activity, which is compatible with all previous activities, so we will start from
the opposite direction of the set. That is,
Now finish time will be considered over start time and hence ai = [fi, , si ). We
can apply the same greedy approach on activities, according to finish time
until when it starts. Basically the greedy approach will work in reverse
direction.
Therefore, it will have same running time and optimal solution to the
problem.

4.
|--1---|
|-------2----------|
|--------3--------|

Selecting activity with least duration:


Selecting activity with least duration will yield {1}, but optimal
solution is {2, 3}

|---1---|
|--2--|
|---3---|
|--4--|
|--5--|
|--6--|
|--7--|
|---8---|
|---9---|

Select activity with minimum overlapping:


Selecting activity according to this criterion will yield {2}, but optimal
solution is {4,5,6,7}
|-------1--------|
|-----2----|
|----3---|

Selecting activity with earliest start time:


Selecting activity according to this criterion will yield {1}, but again optimal
solution is {2,3}
We can clearly see that these 3 greedy approaches dont yield maximum size
set of mutually compatible activities.

5. let there be n knapsacks, k<k1, k2, k3. kn> with value and weight given
as ki =[vi, wi]. now our job is to maximize the fraction of weight from
knapsack to reach threshold limit of weight.
We choose the highest value by weight of any knapsack until the knapsack is
emptied out , and then we choose the next highest value by weight of other
knapsack and then repeat it. So our main aim is to choose next highest value
by weight of knapsack, which is what a greedy algorithm does.
Therefore, fractional knapsack is greedy-choice property.

You might also like