Last active
September 30, 2018 00:10
-
-
Save laran/4a767ac2ee9941a07df573b1ef3cc12a to your computer and use it in GitHub Desktop.
An Adjacency Matrix representation of a Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - 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