Figure 2-3. A sample graph used to illustrate various graph representations
Tip
■
For tools to help you visualize your own graphs, see the sidebar “Graph Libraries” later in this chapter.
To begin with, assume that we have numbered the nodes, that is, a = 0, b = 1, and so forth. The graph can then
be represented in a straightforward manner, as shown in Listing 2-1. Just as a convenience, I have assigned the node
numbers to variables with the same names as the node labels in the figure. You can, of course, just work with the
numbers directly. Which adjacency set belongs to which node is indicated by the comments. If you want, take a
minute to confirm that the representation does, indeed, correspond to the figure.
Chapter 2
■
the BasiCs
25
Do'stlaringiz bilan baham: |