Preferential attachment is a common phenomenon in complex network where nodes with more connections are more likely to establish new connections. When both nodes possess a large number of connections, the probability of them forming a connection is significantly higher. This phenomenon was utilized by A. Barabási and R. Albert in their proposed BA model for generating random scale-free networks in 2002:
The Preferential Attachment algorithm gauges the similarity between two nodes by calculating the product of the number of neighbors each node has. It is computed using the following formula:

where N(x) and N(y) are the sets of adjacent nodes to nodes x and y respectively.
Higher Preferential Attachment scores indicate greater similarity between nodes, while a score of 0 indicates no similarity between two nodes.

In this example, PA(D,E) = |N(D)| * |N(E)| = |{B, C, E, F}| * |{B, D, F}| = 4 * 3 = 12.
algo(topological_link_prediction)Name | Type | Spec | Default | Optional | Description |
|---|---|---|---|---|---|
| ids / uuids | []_id / []_uuid | / | / | No | ID/UUID of the first set of nodes to calculate; each node in ids/uuids will be paired with each node in ids2/uuids2 |
| ids2 / uuids2 | []_id / []_uuid | / | / | No | ID/UUID of the second set of nodes to calculate; each node in ids/uuids will be paired with each node in ids2/uuids2 |
| type | string | Preferential_Attachment | Adamic_Adar | No | Type of similarity; for Preferential Attachment, keep it as Preferential_Attachment |
| limit | int | >=-1 | -1 | Yes | Number of results to return, -1 to return all results |
The example graph is as follows:

| Spec | Content |
|---|---|
| filename | node1,node2,num |
UQLalgo(topological_link_prediction).params({ uuids: [3], uuids2: [1,5,7], type: 'Preferential_Attachment' }).write({ file:{ filename: 'pa' } })
Results: File pa
FileC,A,3.000000 C,E,6.000000 C,G,3.000000
| Alias Ordinal | Type | Description | Columns |
|---|---|---|---|
| 0 | []perNodePair | Node pair and its similarity | node1, node2, num |
UQLalgo(topological_link_prediction).params({ ids: 'C', ids2: ['A','C','E','G'], type: 'Preferential_Attachment' }) as pa return pa
Results: pa
| node1 | node2 | num |
|---|---|---|
| 3 | 1 | 3 |
| 3 | 5 | 6 |
| 3 | 7 | 3 |
| Alias Ordinal | Type | Description | Columns |
|---|---|---|---|
| 0 | []perNodePair | Node pair and its similarity | node1, node2, num |
UQLfind().nodes() as n with collect(n._id) as nID algo(topological_link_prediction).params({ ids: 'C', ids2: nID, type: 'Preferential_Attachment' }).stream() as pa where pa.num >= 2 return pa
Results: pa
| node1 | node2 | num |
|---|---|---|
| 3 | 2 | 12 |
| 3 | 4 | 12 |
| 3 | 5 | 6 |
| 3 | 6 | 9 |