Skip to content

Instantly share code, notes, and snippets.

@GitEliteNovice
Last active May 22, 2019 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GitEliteNovice/2ed4f79393b8edb09328c66abae4f089 to your computer and use it in GitHub Desktop.
Save GitEliteNovice/2ed4f79393b8edb09328c66abae4f089 to your computer and use it in GitHub Desktop.
Greedy Knapsack
{
for i=1 to n //step1
{
compute pi/wi; //step2
}
sort objects in non- increasing order p/w; //step3
for i=1 to n //step4
if(m>0 && wi<=m) //step5
m = m - wi; //step6
P = P + pi; //step7
else //step8
break; //step9
if(m>0) //step10
P=P+ pi*(m/wi); //step11
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment