Adjacency Matrix | Sololearn: Learn to code for FREE!

0

Adjacency Matrix

Can someone try and explain for me how this applies in graphs. Thanks πŸ™πŸ½

10/27/2018 7:38:06 AM

Romo

6 Answers

New Answer

+2

Edges go between 2 vertices. Say you have a graph that looks like a -> b -> c You could store the edges in a list of pairs, like [(a, b), (b, c)]. And that's your adjacency list. Another way to do it is to make a table where you mark what is connected to what, like a b c a X X b X X c X (a->a is assumed to be true here) Now replaces all Xs with 1 and the others with 0. Your adjacency matrix is 1,1,0, 0,1,1, 0,0,1

+1

Of course they are, but I'm talking about consistency. Your "diagram" and adjacency list didn't have them.

0

Schindlabua nicely explained. But those three 1s along the diagonal correspond to loops (edge connecting a vertex to itself). So they shouldn't really be there.

0

Depends on your graph. Loops in a graph are fine!

0

Yeah, good point!

0

thank you man!!!