Search code examples
data-structuresgraphadjacency-matrix

Graph representation


Given graph, how could i represent it using adj matrix?. I have read lots of tutorials, post, slides, etc but i cant get my head round it, i just need that little push.

alt text


Solution

  • Every letter-number combination is one node in your graph, i.e., from A0, A1, A2, ... to F5, F6, F7. Your graph has 48 (8 columns times 6 rows in your maze) nodes, so you'll need a 48x48 matrix. If you treat it as boolean, you'll set all fields to false except the ones where there is a connection between two nodes, e.g. A0 to A1 would mean that the A0 row has a true value in the A1 column, and vice versa (because your graph is undirected).