Search code examples
graph-theoryadjacency-matrix

Matrix to Graph?


I have a text file that has the following input and i'm asked to draw graphs from the input but i'm not quite sure how each input turned into the given graphs. I know the first line means number of vertices but next lines don't look like a symmetrical matrix to me!! I understand the first two graphs but after that not sure! I know it's trivial but Please help.

1

2 
1

4
101
 10
  1
5
0011
 011
  11
   0

5
1000
 101
  10
   1 

6
11110
 1011
  101
   11
    1

6
11100
 1010
  001
   00
    0

enter image description here


Solution

  • Have a look at your thrid example in the picture, a typical matrix encoding would be:

      0123
    0 0101
    1 1010
    2 0101
    3 1010
    

    meaning that node 0 is not adjacent to itself (node 0), adjacent to 1, not adjacent to 2 and adjacent to 3, etc. This is a Adjacency matrix.

    It seems that you are dealing with undirected graphs, so the adjacency matrix would contain redundant information, when you know that 0 is adjacent to 1, you know that 1 is adjacent to 0, no need to write that information a second time. Therefore it makes sense to have a slightly different encoding, eliminating all redundance. Under the assumption that a node cannot be adjacent to itself and that your fourth example, in the picture, is supposed to represent the fourth encoding:

      1234
    0 0011
    1  011
    2   11
    3    0 
    

    I would interpret as follows, that node 0 is not adjacent to 1, not adjacent to 2, but adjacent to 3 and 4. Node 1 is not adjacent to 2, but adjacent to 3 and 4, etc. As you can see, you have described the relation of node 0 to node 1 in the first row, so you don't need to describe that in the second row again.