Skip to content

machester4/greedy-approximation-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Greedy approximation algorithm

This solution was initially intended to solve problems similar to the knapsack 0/1 or subset sum problem.

Example: consider the list of numbers [100, 210, 260, 80, 90] 
If the target = 500 then the best solution is 
[100, 210, 80, 90] = 480.

Understanding the algorithm

To understand how it works we will use smaller values.
[15, 4, 4, 2, 1, 0.80, 0.50, 0.49] is the list of values.
9.99 is the target.

Using the algorithm

    // Create a new GreedyApproximation instance
    grapprox := calculator.NewGreedyCalculator(items, maxAmount)

    // Calculate the best solution
    bestSolution := grapprox.Calculate(context.Background())

    // Print the best solution
    fmt.Println(bestSolution)

References

About

Greedy approximation algorithm to solve subset sum problems

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages