5.3 KiB
5.3 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d8256367417b2b2512c79 | Incidence Matrix | 1 | 301644 | Матрица инцидентов |
Description
1Ниже приведен пример
---
1 | 1
2 | 0
3 | 1
incidence matrix
с 4 ребрами и 4 узлами. Помните, что столбцы - это ребра, а строки - сами узлы. 1 2 3 4Ниже приведена реализация JavaScript того же самого.
--------
1 | 0 1 1 1
2 | 1 1 0 0
3 | 1 0 0 1
4 | 0 0 1 0
var incMat = [Чтобы создать ориентированный граф, используйте
[0, 1, 1, 1],
[1, 1, 0, 0],
[1, 0, 0, 1],
[0, 0, 1, 0]
];
-1
для края, оставляющего определенный узел, и 1
для края, входящего в узел. var incMatDirected = [Графики также могут иметь веса по краям. До сих пор у нас есть невзвешенные края, где только наличие и отсутствие ребра двоично (
[0, -1, 1, -1],
[-1, 1, 0, 0],
[1, 0, 0, 1],
[0, 0, -1, 0]
];
0
или 1
). Вы можете иметь разные веса в зависимости от вашего приложения. Другой вес представлен как числа больше 1.
Instructions
Tests
tests:
- text: <code>incMatUndirected</code> should only contain five nodes.
testString: assert((incMatUndirected.length === 5) && incMatUndirected.map(function(x) { return x.length === 4 }).reduce(function(a, b) { return a && b }) );
- text: There should be a first edge between the first and second node.
testString: assert((incMatUndirected[0][0] === 1) && (incMatUndirected[1][0] === 1));
- text: There should be a second edge between the second and third node.
testString: assert((incMatUndirected[1][1] === 1) && (incMatUndirected[2][1] === 1));
- text: There should be a third edge between the third and fifth node.
testString: assert((incMatUndirected[2][2] === 1) && (incMatUndirected[4][2] === 1));
- text: There should be a fourth edge between the second and fourth node.
testString: assert((incMatUndirected[1][3] === 1) && (incMatUndirected[3][3] === 1));
Challenge Seed
var incMatUndirected = [
];
Solution
var incMatUndirected = [[1, 0, 0, 0],[1, 1, 0, 1],[0, 1, 1, 0],[0, 0, 0, 1],[0, 0, 1, 0]];