Giter VIP home page Giter VIP logo

o-1-is-linked-graph's Introduction

O-1-is-linked-Graph

A graph implementation to do a check to see if two nodes are linked in O(1) time complexity.

Usage:

  1. add 1 2
  2. remove 1 2
  3. is linked 1 2

Assumption:

  1. The implementation assumes that there would not be multiple links between 2 same nodes as there is no concept of weights in this situation. If we need to accomodate such a scenario, we could add a count to the neighbor list.
  2. The implementation assumes that only integer values would be passed in. So, i have not added checks for non-integer value to discard them as bad input.

Note: This is not a thread-safe implementation.

Complexity:

  1. Space Complexity: The Graph representation would take O(V+E) space. The intNodeMap would take O(V) space. The intClusterMap would take O(V) space as each node is mapped to a cluster and each Node could potentially map to its own cluster as worst case.
  2. Add link time complexity: Add would take O(V) time as it loops over all the clusters once and loops over nodes in one cluster once.
  3. Remove link time complexity: O(V+E) as we are doing a DFS using adjacency lists.
  4. 'Is linked' time complexity: O(1) as all the processing is done during add and remove.

o-1-is-linked-graph's People

Contributors

nahzor avatar

Stargazers

 avatar

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.