UltipaDocs
Try Playground
  • Introduction
  • Managing HDC Graphs
  • Managing Distributed Projections
  • Installing Algorithms
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • K-Hop All
    • Bipartite Graph
    • HyperANF
    • Connected Component
    • Triangle Counting
    • Induced Subgraph
    • k-Core
    • k-Truss
    • p-Cohesion
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Topological Sort
    • Schema Overview
    • Dijkstra's Single-Source Shortest Path
    • Delta-Stepping Single-Source Shortest Path
    • Shortest Path Faster Algorithm (SPFA)
    • Minimum Spanning Tree
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Louvain
    • Leiden
    • Label Propagation
    • HANP
    • k-Means
    • kNN (k-Nearest Neighbors)
    • K-1 Coloring
    • Conductance
      • Random Walk
      • Node2Vec Walk
      • Node2Vec
      • Struc2Vec Walk
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Analytics & Algorithms
  4. /
  5. Connectivity & Compactness

Bipartite Graph

HDC

Overview

The Bipartite algorithm is used to determine whether a given graph is a bipartite graph. The algorithm identifies and leverages the structure of bipartite graphs to enable efficient resource allocation, task assignment, and group optimization in various scenarios.

The Bipartite algorithm returns 1 if the graph is bipartite; otherwise, it returns 0.

Concepts

Bipartite Graph

A bipartite graph, also known as a bigragh, is a graph in which the nodes can be divided into two disjoint sets such that every edge connects a node from one set to a node in the other. In other words, no edge connects nodes within the same set.

This example graph is bipartite. The nodes can be partitioned into sets V1 = {A, D, E} and V2 = {B, C, F}.

Coloring Method

To determine if a graph is bipartite, one common approach is to perform a graph traversal and assign each visited node to one of two different sets. This process is often referred to as "coloring" the nodes. During traversal, if an edge is found that connects two nodes within the same set, the graph is not bipartite. Conversely, if all edges connect nodes from different sets, the graph is bipartite.

In this example, both graph A and graph B are bipartite. Graph C is not bipartite as it contains an odd cycle. An odd cycle is a cycle that has an odd number of nodes. Bipartite graphs cannot contain odd cycles, as it is impossible to color all nodes in an odd cycle using only two colors while satisfying the bipartite condition. This property, where bipartite graphs never contain any odd cycles, is a fundamental characteristic of bipartite graphs.

Considerations

  • A self-loop connects a node to itself, meaning both endpoints are the same node. Therefore, any graph containing a self-loop is not bipartite.
  • The Bipartite algorithm ignores the direction of edges but calculates them as undirected edges.

Example Graph

Run the following statements on an empty graph to define its structure and insert data:

INSERT (a:default {_id: "a"}),
       (b:default {_id: "b"}),
       (c:default {_id: "c"}),
       (d:default {_id: "d"}),
       (e:default {_id: "e"}),
       (f:default {_id: "f"}),
       (a)-[:default]->(b),
       (a)-[:default]->(d),
       (c)-[:default]->(b),
       (d)-[:default]->(c),
       (d)-[:default]->(e),
       (e)-[:default]->(b),
       (f)-[:default]->(a),
       (f)-[:default]->(e);

Creating HDC Graph

To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:

CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: true,
  update: "static"
}

Parameters

Algorithm name: bipartite

The algorithm does not require any parameters.

File Writeback

CALL algo.bipartite.write("my_hdc_graph", {}, 
{
  file: {
    filename: "isBipartite"
  }
})
File: isBipartite
bipartite_result: 1

Stats Writeback

CALL algo.bipartite.write("my_hdc_graph", {}, 
{
  stats: {}
})

Result:

bipartite_result
true

Full Return

CALL algo.bipartite.run("my_hdc_graph") YIELD r
RETURN r

Result:

bipartite_result
1

Stream Return

CALL algo.bipartite.stream("my_hdc_graph") YIELD r
RETURN r

Result:

bipartite_result
1

Stats Return

CALL algo.bipartite.stats("my_hdc_graph") YIELD r
RETURN r

Result:

bipartite_result
1