Skip to content

Instantly share code, notes, and snippets.

@laran
Last active September 30, 2018 00:10
Show Gist options
  • Save laran/4a767ac2ee9941a07df573b1ef3cc12a to your computer and use it in GitHub Desktop.
Save laran/4a767ac2ee9941a07df573b1ef3cc12a to your computer and use it in GitHub Desktop.
An Adjacency Matrix representation of a Graph
// - An Adjacency Matrix stores the Set of all possible Edges.
// - Each row represents a Node, storing the complete Set of possible Edges for that Node.
// - The index of the element in the outer Array indicates the ID of the Node.
// - A value of 1 indicates an Edge. A 0 indicates no Edge.
//
// In this example:
// - Node 0 has an Edge to Node 3
// - Node 1 has Edges to Nodes 0 and 3
// - Node 2 has Edges to Nodes 0, 1 and 3
// - Node 3 has an Edge to Node 1
let graph = [
[0, 0, 0, 1],
[1, 0, 0, 1],
[1, 1, 0, 1],
[0, 1, 0, 0],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment