<commit_before>---
id: 587d8256367417b2b2512c78
title: Adjacency Matrix
challengeType: 1
forumTopicId: 301621
---

## Description
<section id='description'>

Another way to represent a graph is to put it in an <dfn>adjacency matrix</dfn>.
An <dfn>adjacency matrix</dfn> is a two-dimensional (2D) array where each nested array has the same number of elements as the outer array. In other words, it is a matrix or grid of numbers, where the numbers represent the edges. Zeros mean there is no edge or relationship.
<blockquote>    1 2 3<br>   ------<br>1 | 0 1 1<br>2 | 1 0 0<br>3 | 1 0 0</blockquote>
Above is a very simple, undirected graph where you have three nodes, where the first node is connected to the second and third node. <strong>Note</strong>: The numbers to the top and left of the matrix are just labels for the nodes.
Below is a JavaScript implementation of the same thing.

```js
var adjMat = [
  [0, 1, 1],
  [1, 0, 0],
  [1, 0, 0]
];
```
<commit_msg>Added meaning of ones in adjacency matrices (#37048)<commit_after>---
id: 587d8256367417b2b2512c78
title: Adjacency Matrix
challengeType: 1
forumTopicId: 301621
---

## Description
<section id='description'>

Another way to represent a graph is to put it in an <dfn>adjacency matrix</dfn>.
An <dfn>adjacency matrix</dfn> is a two-dimensional (2D) array where each nested array has the same number of elements as the outer array. In other words, it is a matrix or grid of numbers, where the numbers represent the edges. 

<strong>Note</strong>: The numbers to the top and left of the matrix are just labels for the nodes. Inside the matrix, ones mean there exists an edge between the vertices (nodes) representing the row and column.  Finally, zeros mean there is no edge or relationship.
<pre>
    1 2 3
  \------
1 | 0 1 1
2 | 1 0 0
3 | 1 0 0
</pre>
Above is a very simple, undirected graph where you have three nodes, where the first node is connected to the second and third node. 
Below is a JavaScript implementation of the same thing.

```js
var adjMat = [
  [0, 1, 1],
  [1, 0, 0],
  [1, 0, 0]
];
```

{'fraction_non_alphanumeric': 0.09296724470134875, 'fraction_numerical': 0.05250481695568401, 'mean_word_length': 3.8078703703703702, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6546388', 'n_tokens_mistral': 729, 'n_tokens_neox': 630, 'n_words': 329}