Giter VIP home page Giter VIP logo

union_find's Introduction

Union Find

This is an implementation of the union_find algorithm.
To compute the connected components of a network you can pass in the network as a collection of nodes with their neighbors as std::vector<std::set < std::string>>* to the function run_connected_component. This function returns, as function's output argument, the pointer to a std::unordered_set where the key is the name of the smallest node in the component (alphabetically smallest name), and the value is a vector of names of all the nodes present in that component.
Todo: change std::set to a template type that will allow for accepting more efficient data structures as well.

Usage:

//edges: 1 <-> 2, 1 <-> 3, 4 <-> 5
//generating the example network:
std::vector<std::set<std::string>> neighbors_list;
std::string neighbors1[] = {"n1", "n2", "n3"};
neighbors_list.push_back (std::set<std::string>(neighbors1, neighbors1 + 3));
std::string neighbors2[] = {"n1", "n2"};
neighbors_list.push_back (std::set<std::string>(neighbors2, neighbors2 + 2));
std::string neighbors3[] = {"n1", "n3"};
neighbors_list.push_back (std::set<std::string>(neighbors3, neighbors3 + 2));
std::string neighbors4[] = {"n4", "n5"};
neighbors_list.push_back (std::set<std::string>(neighbors4, neighbors4 + 2));
neighbors_list.push_back (std::set<std::String>(neighbots4, neighbors4 + 2));

//computing the connected components:
UnionFind ufo();
std::unordered_set<std::string, std::vector<std::string>>* connected_components;
ufo.run_connected_component(&neighbors_list, &connected_components);

//resulting connected components: <n1, [n1, n2, n3]>, <n4, [n4, n5]>

union_find's People

Contributors

armenabnousi avatar armensly avatar

Watchers

 avatar  avatar

Forkers

armensly

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.