Chapter 12 GRAPHS 1. Mathematical Background L 2 Computer Representation L3. Graph Traversal 4.Topological Sorting 5. A Greedy algorithm: Shortest Paths 6. Minimal Spanning trees 7. Graphs as Data Structures
Chapter 12 GRAPHS 1. Mathematical Background 2. Computer Representation 3. Graph Traversal 4. Topological Sorting 5. A Greedy Algorithm: Shortest Paths 6. Minimal Spanning Trees 7. Graphs as Data Structures
12.1 Mathematical Background Definitions and Examples 关联 1. A graph G consists of a set V, wh se mem ers are called the vertices of G, together with a set A f pairs of distinct vertices from V 2. The pairs in E are called the edges of G 3. If e=(v,w)is an edge with vertices v and w,then v and w are said to lie on e, and e is said to be incident with v and w 4. If the pairs are unordered, G is called an undirected graph 5. If the pairs are ordered, G is called a directed graph. The term directed graph is often shortened to digraph, and the unqualified term graph usually means undirected graph
12.1 Mathematical Background Definitions and Examples 1. A graph G consists of a set V , whose members are called the vertices of G, together with a set E of pairs of distinct vertices from V . 2. The pairs in E are called the edges of G. 3. If e = (v,w) is an edge with vertices v and w, then v and w are said to lie on e, and e is said to be incident with v and w. 4. If the pairs are unordered, G is called an undirected graph. 5. If the pairs are ordered, G is called a directed graph. The term directed graph is often shortened to digraph, and the unqualified term graph usually means undirected graph. 依附于 关联
6. Two vertices in an undirected graph are called adjacent if there is an edge from the first to the second 7. A path is a sequence of distinct vertices, each adjacent to the next 8. a cycle is a path containing at least three vertices such that the last vertex on the path is adjacent to the first 9. a graph is called connected if there is a path from any vertex to any other vertex 10. A free tree is defined as a connected undirected graph with no cycles 11. In a directed graph a path or a cycle means always moving in the direction indicated by the arrows Such a path(cycle)is called a directed path(cycle)
6. Two vertices in an undirected graph are called adjacent if there is an edge from the first to the second. 7. A path is a sequence of distinct vertices, each adjacent to the next. 8. A cycle is a path containing at least three vertices such that the last vertex on the path is adjacent to the first. 9. A graph is called connected if there is a path from any vertex to any other vertex. 10. A free tree is defined as a connected undirected graph with no cycles. 11. In a directed graph a path or a cycle means always moving in the direction indicated by the arrows. Such a path (cycle) is called a directed path (cycle)
12.a directed graph is called strongly connected if there is a directed path from any vertex to any other vertex. If we suppress the direction of the edges and the resulting undirected graph is connected, we call the directed graph weakly connected. 13.The valence of a vertex is the number of edges on which it lies, hence also the number of vertices adjacent to it
12.A directed graph is called strongly connected if there is a directed path from any vertex to any other vertex. If we suppress the direction of the edges and the resulting undirected graph is connected, we call the directed graph weakly connected. 13.The valence of a vertex is the number of edges on which it lies, hence also the number of vertices adjacent to it
Examples of Graphs Honolulu H C Samoa Fiji C C Noumea Tahiti H Sydney Auckland Benzene molecule Selected south pacific air routes
Examples of Graphs
B A F C E essage transmission In a netwo rk 21○○21Q 21 3 Connected Path Cycle Disconnected Tree Various kinds of undirected graphs
Various kinds of undirected graphs
Directed cycle Strongly connected Weakly connected Examples of directed graphs
Examples of directed graphs
12.2 Computer Representation Set Implementations of Digraphs pg 573 Definition a digraph G consists of a set V, called the vertices of G, and, for all VE V, a subset Av of V, called the set of vertices adjacent to v directed graph
12.2 Computer Representation Set Implementations of Digraphs pg.573 Definition A digraph G consists of a set V , called the vertices of G, and, for all vV, a subset Av of V, called the set of vertices adjacent to v. directed graph
number of vertices Set as a bit string: pg 573 at most max size template struct Set I bool is_element[max_set]s Digraph as a bit-strip set template class Digraph I int count Set neighbors[max size];
Digraph as a bit-string set: template class Digraph { int count; Set neighbors[max_size]; }; number of vertices at most max_size Set as a bit string: pg.573 template struct Set { bool is_element[max_set]; };
Adjacency matrix Digraph as an adjacency table: pg 57 template class digraph int count. bool adjacency[max size[max size]
Digraph as an adjacency table: pg.574 template class Digraph { int count; bool adjacency[max_size][max_size]; }; Adjacency matrix