# Preferential Attachment

Supported Graph Characteristics
 Unweighted edges Directed edges Undirected edges Homogeneous vertex types Heterogeneous vertex types

Preferential Attachment is a measure to compute the closeness of vertices based on the number of their neighbors. The algorithm returns the product of the number of neighbors of the first vertex and the number of neighbors of the second vertex.

## Notes

Preferential attachment as a metric works best on graphs that have an "unequal" structure where a majority of vertices have few connections and a minority of vertices have many connections.

This algorithm ignores edge weights.

## Specifications

``````CREATE QUERY tg_preferential_attachment(VERTEX v_source VERTEX v_target,
SET<STRING> e_type)``````

### Parameters

Name Description Data type

`VERTEX v_source`

The first vertex to compare. Provide the vertex ID and type as a tuple: `("id","type")`

N/A

`VERTEX v_target`

The second vertex to compare with the first. Provide the vertex ID and type as a tuple: `("id","type")`

N/A

`SET<STRING> e_type_set`

Edge types to traverse.

(A blank set of strings)

### Time complexity

The algorithm has a time complexity of $O(D1 + D2)$, where $D1$ and $D2$ are the degrees of the two vertices.

## Return value

The product of the number of neighbors of the two vertices.

## Example

Suppose we have the following graph: Since Dan has four neighbors, while Jenny has three, the return value of the algorithm is $3*4=12$.

• Query

• Result

``RUN QUERY preferential_attachment (("Jenny", "person"), ("Dan", "person"), ["friendship"])``
``````{
"error": false,
"message": "",
"version": {
"schema": 1,
"edition": "enterprise",
"api": "v2"
},
"results": [{"closeness": 12}]
}``````