Professional Documents
Culture Documents
Graphs
Graphs
21
Basic concepts
A graph G consists of two sets
– a finite, nonempty set of vertices V(G)
– a finite, possible empty set of edges E(G)
– G(V,E) represents a graph
An undirected graph is one in which the pair of vertices in a edge
is unordered, (v0, v1) = (v1,v0)
A directed graph is one in which each edge is a directed pair of
vertices, <v0, v1> != <v1,v0>
Definition: Directed graph
• Directed Graph
– A directed graph, or digraph, is a pair
– G = (V, E)
– where V is a set whose elements are called vertices, and
– E is a set of ordered pairs of elements of V.
Chicago
Seattle
San Francisco
Dallas
p = {Seattle, Salt Lake City, Chicago, Dallas, San Francisco, Seattle}
Path Length and Cost
Path length: the number of edges in the path
Path cost: the sum of the costs of each edge
3.5 Chicago
Seattle
2 2
3
San Francisco
Dallas
length(p) = 5 cost(p) = 11.5
Connectivity
Undirected graphs are connected if there is a path between any two
vertices
Directed graphs are strongly connected if there is a path from any one
vertex to any other
I J
Directed Acyclic Graphs (DAGs)
mult()
if program call
graph is a DAG, then add()
all procedure calls
can be in-lined
read()
access()