Git Product home page Git Product logo

bipartite-testing's Introduction

Bipartite Graph Testing Algorithm

Modification of Breadth First Serach to check if a graph is bipartite
Uses the same BFS approach as I use in BFS/DFS Algorithms

Bipartite Graphs

A bipartite graph is one that can be partitioned into 2 sets of vertices where no edge has both end-nodes in the same set
A helpful abstraction is to imagine coloring the vertices 1 of 2 colors so that every edge has end-nodes of different colors

This is the 1st graph tested in the code

An important property of Bipartite graphs is they contain NO odd-length cycle
A Bipartite Graph (even length cycle)

A Non-Bipartite Graph (odd length cycle CANNOT be colored & still maintain edges with different colored end-nodes)

This is the 2nd graph that the code tests

Algorithm

  • Modification of Breadth First Search
  • Explore from any arbitrary node
  • Color all nodes in a layer of BFS Red if if layer number is even, Blue if odd
  • Scan edges to see if any edge with the same color on both ends (return false if that's the case)

Code Notes

  • Uses an adjacency list graph representation
  • String[] color is calculated during BFS based on if layerCounter is even or odd

bipartite-testing's People

Contributors

sleekpanther avatar

Watchers

 avatar  avatar

Forkers

viji0990

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.