## 7.3.Computing Paths from a Matrix Representation

Let G = (V, E) be a simple digraph in which V = { } and the nodes are assumed to be ordered from to

The n × n matrix A whose elements are given by:

is called adjacency matrix of the graph G.

Examples:

Page 379

Examples:

• in a computer language
``` 1      /*
2       *      Representation of a graph
3       */
4
5      int main(void)
6      {
7              {       /* b    */
8              static char first[256][256];
9
10              /* init */
11              first['a'][0] = 'b';
12              first['a'][1] = 'c';
13              first['a'][2] = 'd';
14
15              first['b'][0] = 'a';
16              first['b'][1] = 'c';
17              first['b'][2] = 'e';
18
19              first['c'][0] = 'd';
20              first['c'][1] = 'f';
21
22              first['d'][0] = 'e';
23              first['d'][1] = 'f';
24
25              first['e'][0] = 'f';
26
27              /* use */
28              printf("matrix:\n");
29              printf("a's neighbor = ");
30              putchar(first['a'][0]);
31                      putchar('\n');
32              printf("a's neighbor = ");
33              putchar(first['a'][1]);
34                      putchar('\n');
35              printf("a's neighbor = ");
36              putchar(first['a'][2]);
37                      putchar('\n');
38              }
40              {
41      #       define newNode calloc(1,        \
42                      sizeof ( struct NodeStruct))
43
44              typedef struct NodeStruct * NodeP;
45              struct NodeStruct {
46                      char node;
47                      NodeP next;
48                } NodeStruct;
49
50              struct NodeStruct a, b, c, d, e;
51
52              a.node = 'a'; a.next = newNode;
53              a.next-->node = 'b';
54
55              a.next-->next = newNode;
56              a.next-->next-->node = 'c';
57
58              a.next-->next-->next = newNode;
59              a.next-->next-->next-->node = 'd';
60              /* and so on    */
63              /* use */
64              printf("list:\n");
65              printf("a's neighbor = ");
66              putchar(a.next-->node);
67                      putchar('\n');
68              printf("a's neighbor = ");
69              putchar(a.next-->next-->node);
70                      putchar('\n');
71              printf("a's neighbor = ");
72              putchar(a.next-->next-->next-->node);
73                      putchar('\n');
74              /* and so on    */
75              exit(0)
76              }
77      }
```