Same Community

Algorithm link: Same Community

This algorithm takes two vertices as input, returning 1 if the two vertices are in the same community, and returning 0 if they are not in the same community.

The algorithm assumes that community detection has already completed and that a community ID is stored in an integer attribute on each vertex.

Specifications

CREATE QUERY tg_same_community(VERTEX a, VERTEX b, STRING
    communityAttribute)

Time complexity

The algorithm has a time complexity of \$O(1)\$.

Parameters

Name Description Data type

a

A vertex.

VERTEX

b

A vertex.

VERTEX

communityAttribute

The community attribute used to store a vertex’s community ID.

STRING

Return value

  • Returns 1 if the two vertices are in the same community.

  • Returns 0 if the two vertices are not in the same community.

Example

Suppose we have the following vertices:

same community ex

Their community IDs were generated by running the weakly connected component algorithm on the graph. If we run the algorithm between Kevin and Jenny, we get 1 because the two vertices are in the same community as indicated by their community attribute:

  • Query

  • Result

RUN QUERY tg_same_community (("Jenny", "person"), ("Kevin", "person"), "community")
{
  "error": false,
  "message": "",
  "version": {
    "schema": 2,
    "edition": "enterprise",
    "api": "v2"
  },
  "results": [{"1": 1}]
}