Adjacency Matrix

Representing a Weighted Graph with an adjacency matrix in JavaScript post by Regina Furness

So to represent a graph as an adjacency matrix, we will use the intersections of the columns and rows to represent an edge. For an unweighted graph, that intersection will just have a value of 1 to represent an edge between two vertices. For a weighted graph, we will simply put the weight as the value at that intersection. Let’s take this undirected, weighted graph:

First let’s just look at it represented as a grid, so you can see what I mean when I say ‘column’ and ‘row’.

A B C D A 0 2 3 0 B 2 0 0 2 C 3 0 0 6 D 0 2 6 0

Now, as an actual matrix:

[[0, 2, 3, 0], [2, 0, 0, 2], [3, 0, 0, 6], [0, 2, 6, 0]]

You can see an undirected graph will be symmetrical across the top left to bottom right diagonal. Which means, if we have two vertices, i and j, which are connected by an edge, that means `matrix[i][j]` will be equal to `matrix[j][i]`.

# Code

Let’s start with our class constructor. ⇒ Graph

class Graph { constructor(size = 1) { this.size = size; this.matrix = []; for (let i = 0; i < size; i++) { this.matrix.push([]); for (let j = 0; j < size; j++) { this.matrix[i][j] = 0; } } } }

[…]

~

Representing a Weighted Graph with an adjacency matrix in JavaScript post by Regina Furness

Here we list a few pages and sites about graph and network visualisation as it relates to FedWiki.

Information about the relative importance of nodes and edges in a graph can be obtained through Centrality measures, widely used in disciplines like Sociology. For example, eigenvector centrality uses the eigenvectors of the adjacency matrix corresponding to a network, to determine nodes that tend to be frequently visited. Formally established measures of centrality are degree centrality, closeness centrality, betweenness centrality, eigenvector centrality, subgraph centrality and Katz centrality. The purpose or objective of analysis generally determines the type of centrality measure to be used. For example, if one is interested in dynamics on networks or the robustness of a network to node/link removal, often the dynamical importanceCharacterizing the Dynamical Importance of Network Nodes and Links of a node is the most relevant centrality measure.For a centrality measure based on k-core analysis see ref.[ A model of Internet topology using k-shell decomposition]

The single most undervalued fact of linear algebra: matrices are graphs, and graphs are matrices.