GraphNode

GraphNode

new GraphNode()

Graph node/vertex that can hold adjacent nodes. For performance, uses a Set instead of array for neighbours. Unlike trees, a graph does not have a root node and can be traversed from anywhere.

Source:

Methods

addNeighbour(neighbour)

Add neighbour to the neighbours list Runtime: O(1)

Parameters:
Name Type Description
neighbour GraphNode
Source:

isNeighbour(neighbour)

Checks if the given node is a neighbour

Parameters:
Name Type Description
neighbour GraphNode
Source:

removeNeighbour(neighbour) → {boolean}

Remove given neighbour from the neighbours list. Returns true node or false if node was not found.

Runtime: O(1)

Parameters:
Name Type Description
neighbour GraphNode
Source: