Coder Social home page Coder Social logo

codehardt / go-setcover Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4 KB

Golang implementation of the Greedy Set Cover Algorithm that calculates the smallest combination of sets that covers all elements in that sets.

License: MIT License

Go 100.00%
go golang algorithm setcover sets list elements unique greedy coverage

go-setcover's Introduction

go-setcover

This Golang package calculates the smallest combination of sets that covers all elements in that sets. This is also known as the Set cover problem.

Example:

Consider there are four sets {1, 2, 3}, {2, 4}, {3, 4} and {4, 5}. The smallest possible combination of those sets that still cover all elements is {1, 2, 3}, {4, 5}.

mySets := [][]int{{1, 2, 3}, {2, 4}, {3, 4}, {4, 5}}
minimalIndices := setcover.GreedyCoverageIndex(mySets) // equals []int{0, 3}

Exceptions:

It isn't guaranteed that this package returns the smallest combination of sets because of the usage of the greedy algorithm.

Consider there are five sets {1, 2}, {2, 3, 4, 5}, {6, 7, 8, 9, 10, 11, 12, 13}, {1, 3, 5, 7, 9, 11, 13} and {2, 4, 6, 8, 10, 12, 13}. The optimal combination is {1, 3, 5, 7, 11, 13} and {2, 4, 6, 8, 10, 12, 13} but the greedy algorithm produces {6, 7, 8, 9, 10, 11, 12, 13}, {2, 3, 4, 5}, {1, 2}, because it always searches for the sets with the biggest count of uncovered elements, first.

go-setcover's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.