- Category: ranking and walking
- Algorithm ID: pgx_builtin_k7c_degree_centrality
- Time Complexity: O(V) with V = number of vertices
- Space Requirement: O(V) with V = number of vertices
- Javadoc:
Degree centrality counts the number of outgoing and incoming edges for each vertex in the graph.
Input Argument |
Type |
Comment |
G |
graph |
the graph. |
Output Argument |
Type |
Comment |
dc |
vertexProp |
vertex property holding the degree centrality value for each vertex in the graph. |
Return Value |
Type |
Comment |
|
void |
None |
/*
* Copyright (C) 2013 - 2025 Oracle and/or its affiliates. All rights reserved.
*/
package oracle.pgx.algorithms;
import oracle.pgx.algorithm.annotations.GraphAlgorithm;
import oracle.pgx.algorithm.PgxGraph;
import oracle.pgx.algorithm.VertexProperty;
import oracle.pgx.algorithm.annotations.Out;
import oracle.pgx.algorithm.ControlFlow;
@GraphAlgorithm
public class DegreeCentrality {
public void degreeCentrality(PgxGraph g, @Out VertexProperty<Integer> degreeCentrality) {
long numberOfStepsEstimatedForCompletion = g.getNumVertices();
ControlFlow.setNumberOfStepsEstimatedForCompletion(numberOfStepsEstimatedForCompletion);
g.getVertices().forEach(n ->
degreeCentrality.set(n, (int) (n.getOutDegree() + n.getInDegree()))
);
}
}