Incidence Matrix

Tell us what’s happening:
I’m able to pass everything except for the first test, which seems to check for incMatUndirected.length === 5, which my code appears to satisfy. Please advise.

Your code so far


var incMatUndirected = Array.from({length: 5}, el => Array.from({length:5}, el => 0))

incMatUndirected[0][0] = 1;
incMatUndirected[1][1] = 1;
incMatUndirected[0][1] = 1;
incMatUndirected[1][0] = 1;
incMatUndirected[1][2] = 1;
incMatUndirected[2][1] = 1;
incMatUndirected[2][2] = 1;
incMatUndirected[2][4] = 1;
incMatUndirected[4][2] = 1;
incMatUndirected[4][4] = 1;
incMatUndirected[1][3] = 1;
incMatUndirected[3][1] = 1;
incMatUndirected[3][3] =1;

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/data-structures/incidence-matrix

Yeah… I dunno… I’ve tried all physical configurations I can think of.

Your version is populating a 5x5 to be all 0 for elements, then populating 1’s for the values…

In terms of your code here, the following matrix, right?

var incMat Undirected = [
1: [1,1,0,0,0],
2: [1,1,1,0,0],
3:[0,1,1,0,1],
4: [0,1,0,1,0],
5: [0,0,1,0,1] };

, where each undirected ‘node’ (1 - 5) corresponds to having ‘direct connection’ with a node… Right?

So what were the criteria programmed ? For an undirected graph (or assuming for each undirected edge that corresponds within a network or node-directed graph, each is contingent on edge ‘node’ i existing in its available paths as a binary expression: {possible output binary values: iff undir: (1,0); else (-1) }, whereas a directed graph would care about the specific direction for which the edge is directed and would invert the sign if going in the opp dir. )

Node 1: [2],
Node 2: [1,3,4]
… 3: [2,5]
… 4: [2]
… 5: [3]

This is all HINGING on Node 2, so 3 possibilities…

1: Programmed internally to be wrong? Call Quincy or manufacturer? …
2: (5x4, 5x5 matrix), corresponding to the specific type(s) of nodes and no. edges allocated internally along the path… which I got all but two correct on previous attempts. Idk, idc, tbh…
3: We’re populating wrong (casting the array to be wrong somehow), or not populating the corresponding binary edge weights correctly (?)

I’m still trying to figure out myself, but I’m guessing a combination of Possibilities (1,3).

/* Edges to Nodes Matrix: {1}: {1,2}, {2}:{2,3}, {3}: {3,5}, {4}: {2,4};
Flip Node to Edges-> [{1}: {1}, {2}:{1,2,4}, {3}: {2,3}, {4}: {4}, {5}: {3}] */
undirectedIncidenceMat = [
[1,0,0,0],
[1,1,0,1],
[0,1,1,0],
[0,0,0,1],
[0,0,1,0]
];