next up previous index
Next: Graph representations Up: Data Structures Previous: Code and demonstration   Index


Weighted Graphs

Graphs occur everywhere--not surprisingly, since any binary relation determines a graph. Graphs are often represented pictorially, for example Figures 12.1 and 12.2.

Figure 12.1: An undirected acyclic graph.

\begin{picture}(110,50)(-5,-5)
\put(20,0){\circle{10}}
\put(40,0){\circle{10}}...
...,0){10}}
\put(65,40){\line(1,0){10}}
\put(85,40){\line(1,0){10}}
\end{picture}

Both graphs consist of a collection of nodes connected by various arcs. (A node is often called a vertex and an arc is often called an edge.) In Figure 12.1, the arcs have no particular direction. This is called an undirected graph. The arcs have arrows on them in Figure 12.2. This represents a directed graph.

Figure 12.2: A weighted directed graph.

\begin{picture}(70,40)(-5,-5)
\put(0,30){\circle{10}}
\put(0,30){\makebox(0,0)...
...,5){\makebox(0,0){\rm 87}}
\put(48.5,13.5){\makebox(0,0){\rm 43}}
\end{picture}

Information may be attached to the nodes or arcs of a graph, or to both as in the case of Figure 12.2. In the latter case, the nodes are labelled and the arcs are weighted. Numerical weights are sometimes referred to as costs, especially if they are positive. For example, Figure 12.2 might represent a network of airports, with the weights representing costs of direct flights between them, in terms of time or money.

Graphs may possess or lack various topological properties. For example, Figure 12.1 is said to be an acyclic graph because it possesses no closed paths (cycles). Graphs are said to be connected if there is a (directed) path connecting any two nodes. We shall not pursue these matters further except to note that, in Figure 12.2, you can get from any node in the graph to $F$, but you cannot get from $F$ to anywhere else.

Note that there is at most one directed arc between any two nodes in Figure 12.2. In general we shall allow there to be several arcs in either direction and they can have different weights. For example, there are often several direct flights between two cities in either direction, sometimes with different costs. This is sometimes called a multigraph.



Subsections
next up previous index
Next: Graph representations Up: Data Structures Previous: Code and demonstration   Index
Peter Williams 2005-06-07