Code Monkey home page Code Monkey logo

dsu_cpp17_headerfile's Introduction

Disjoint-Set-Union-Header

forthebadge forthebadge forthebadge

Implementation of Disjoint Set Union Header File(.hpp) from scratch using object oriented design approach.

How to use?

  • disjoint_set.hpp file must be present in the present working directory or its path must be set in the environment variable for the IDE.
  • Compatible C++ versions: C++11, C++14, C++17, C++20

Key Functionalities

  • To create a DSU(Disjoint Set Union) with N groups.
  • To merge two set with given node_ids.
    • Implemented Union-By-Rank to perform optimsed merger of nodes.
  • To find the parent_node for a given input node.
    • Implemented Path Compression to optimise the method.
  • To perform validation of nodes with the given node_id.
  • To detect existence of a cycle by utilising the find_parent method.
  • To obtain the total count of disjoint sets in O(1)
  • To obtain the size of the set to which a given node belongs in O(1)

Sample C++ template:

    #include <bits/stdc++.h>
    #include "disjoint_set.hpp"

    using namespace std;
    int main()
    {
        int N;
        cin>>N;
        disjoint_set<int> ds(N);
        // code goes here
    }      

Methods

disjoint_set:: method()

  • bool is_valid(datatype &)
  • datatype find_parent(datatype)
  • void union_set(datatype, datatype)
  • bool detect_cycle(datatype &, datatype &)
  • datatype get_dsu_count()
  • datatype get_set_count(datatype)

CopyRight & License

MIT LICENSE

Authors

dsu_cpp17_headerfile's People

Contributors

akashchouhan16 avatar aryan-jha29 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

dsu_cpp17_headerfile's Issues

Include IO optimization with the header file.

IO Optimization Needed

  • Header file could include a fast io support built-in, as input-output through the iostream(std::cout and std::cin) object is comparatively slow.
  • Header could include an IIFE so that the io optimization is set as soon as the disjoint_set.hpp header file is included.

Add makefile to allow recompilation of only what is needed

Adding makefile and starter template cpp file as an optional support feature to the header file.

  • Include a template cpp program file (main.cpp) and bind the execution with makefile

What is the need for this additional support?

A makefile is useful because it allows you to recompile only what you need when you make a change (if correctly defined). Because there will be many files to be compiled and linked, as well as documentation, tests, and examples, recreating the programme in a large project can take a long time.

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.