mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Added density calculation
This commit is contained in:
11
Graphs/Density.js
Normal file
11
Graphs/Density.js
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
The density of a network is a measure of how many edges exist proportional to
|
||||
how many edges would exist in a complete network (where all possible edges).
|
||||
https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.classes.function.density.html
|
||||
*/
|
||||
function density (numberOfNodes, numberOfEdges, isDirected = false) {
|
||||
const multi = isDirected ? 1 : 2
|
||||
return (multi * numberOfEdges) / (numberOfNodes * (numberOfNodes - 1))
|
||||
}
|
||||
|
||||
(() => { console.log(density(10, 2)) })()
|
Reference in New Issue
Block a user