Basic
Overview
Common neighbors refer to the nodes that have edges to two given nodes. Calculation of common neighbors is also used in the Jaccard Similarity algorithm.
Basic Concept
Neighbors
Neighbors are nodes that are connected with node A by edges, and node A itself is not included (suppose A has self-loop edge). Common neighbors are nodes that have edges connected with both node A and B, and are not node A or B. This definition is consistent with the definition of common neighbors in the Jaccard Similarity algorithm: Include neither duplicated neighbors nor nodes to be compared.

In the graph above, the number of common neighbors of the red and green nodes is 2.
Special Case
Lonely Node, Disconnected Graph
Lonely node does not have any neighbor node, the number of common neighbor between lonely node and any node is 0.
For two nodes belong to different connected components, the number of their common neighbor must be 0.
Self-loop Edge
Self-loop edge of a node does not increase the number of neighbors of the node.
Directed Edge
For directed edges, Common Neighbors algorithm ignores the direction of edges but calculates them as undirected edges.
Results and Statistics
Take the graph below as an example, run the Common Neighbor algorithm:

Algorithm results: Calculate A's common neighbors with B, C and D, return node1
, node2
, num
or return node1
, node2
, ids
according to the result type
node1 | node2 | num |
---|---|---|
1 | 2 | 2 |
2 | 3 | 0 |
3 | 4 | 2 |
node1 | node2 | ids |
---|---|---|
1 | 2 | 6,9, |
2 | 3 | |
3 | 4 | 8,9, |
Algorithm statistics: N/A
Command and Configuration
- Command:
algo(common_neighbours)
- Configurations for the parameter
params()
:
Name | Type | Default Value | Specification | Description |
---|---|---|---|---|
ids / uuids | []_id / []_uuid |
/ | Mandatory | IDs or UUIDs of the first set of nodes to be calculated |
ids2 / uuids2 | []_id / []_uuid |
/ | Mandatory | IDs or UUIDs of the second set of nodes to be calculated |
type | int | 1 | 1 or 2 | 1 or if not set means to return the number of common neighbors, 2 means to return the common neighbors list |
limit | int | -1 | >=-1 | Number of uuids ×uuids2 pairs to return; return all results if sets to -1 or not set |
Algorithm Execution
Task Writeback
1. File Writeback
File Configuration Item | Data in Each Row |
---|---|
filename | node1 ,node2 ,num or node1 ,node2 ,_uuid ,_uuid ,... |
Example: Pairing node UUID = 1 and UUID = 2,3,4, calculate common neighbors of each pair, write the algorithm results back to file named cn
algo(common_neighbours).params({
uuids: 1,
uuids2: [2,3,4],
type: 2
}).write({
file:{
filename: "cn"
}
})
2. Property Writeback
Not supported by this algorithm.
3. Statistics Writeback
This algorithm has no statistics.
Direct Return
Alias Ordinal | Type | Description | Column Name |
---|---|---|---|
0 | []perNodePair | Node pairs and their number of common neighbors or Node pairs and their common neighbors list | node1 , node2 , num or node1 , node2 , ids |
Example: Pairing node UUID = 1 and UUID = 2,3,4, calculate common neighbors of each pair, define algorithm results (common neighbors list) as alias named neighbors, and return the results
algo(common_neighbours).params({
uuids: 1,
uuids2: [2,3,4],
type: 2
}) as neighbors
return neighbors
Example: Pairing node UUID = 1,2 and UUID = 3,4, calculate common neighbors of each pair, define algorithm results (number of common neighbors) as alias named count, and return the results
algo(common_neighbours).params({
uuids: [1,2],
uuids2: [3,4]
}) as count
return count
Streaming Return
Alias Ordinal | Type | Description | Column Name |
---|---|---|---|
0 | []perNodePair | Node pairs and their number of common neighbors or Node pairs and their common neighbors list | node1 , node2 , num or node1 , node2 , ids |
Example: Pairing node UUID = 1 and UUID = 2,3,4, calculate common neighbors of each pair, define algorithm results as alias named count, and return the results which have more than 0 common neighbors
algo(common_neighbours).params({
uuids: 1,
uuids2: [2,3,4]
}).stream() as count
where count.num > 0
return count
Real-time Statistics
This algorithm has no statistics.