A simple undirected graph object with nodes and implicit edges
(Object)
: The nodes in the graph
(number)
: The number of nodes
(number)
: The number of edges
Example valid graph parameter
{ nodes: [
{ id: 1, props: { weight: 0, nType: 1 } },
{ id: 2, props: { weight: 0, nType: 1 } },
{ id: 3, props: { weight: 1, nType: 2 } },
{ id: 4, props: { weight: 2, nType: 2 } }
],
edges: [
[1, 3],
[3, 4],
[4, 2]
] }
Add a new undirected edge by connecting two nodes that both exist.
Does not allow self edges by way of being a simple graph
boolean
:
True if able to add edge, false otherwise (i.e., self
edge, redundant, or invalid source/target)
The same as addEdge, but will create new nodes if source or target does not exist
boolean
:
True if able to add edge, false otherwise (i.e., self
edge, redundant, or invalid source/target)
A node in a graph
(number)
The ID of the node to create
A runner for Dijkstra's shortest path algorithm
Run Dijkstra's algorithm to find the shortest path from one node to another
(Graph)
The graph on which to run the algorithm
(number)
The value of node type (nType) that is a valid path
(number)
The ID of the starting point
(number)
The ID of the ending point
Object
:
The results of running Dijkstra's algorithm, or null if
the source/target do no exist
The format of the results
{
source: < The ID of the node that served as the source >
target: < The ID of the node that served as the target >
dist: < The dist of each node from source (Infinity if not reached) >
prev: < The previous node along the optimal path from the source (null if not reached) >
}
A binary min heap implemented with an array
(function)
Must return the property used for ordering
(function)
Must return the property used as the key
(Array)
: The elements in the array-implemented heap
(function)
: A function that returns the property
used for ordering the elements
(function)
: A function that returns the property
used as the key of the elements