- 1
- 0
- 约1.57万字
- 约 43页
- 2018-06-10 发布于河南
- 举报
ELABORATIONS(细节)
CHAPTER 22: ELEMENTARY GRAPH ALGORITHMS This chapter presents methods for representing a graph and for searching a graph. Searching a graph means systematically following the edges of the graph so as to visit the vertices of the graph. A graph-searching algorithm can discover much about the structure of a graph. Many algorithms begin by searching their input graph to obtain this structural information. Other graph algorithms are organized as simple elaborations(细节) of basic graph-searching algorithms. Techniques for searching a graph are at the heart of the field of graph algorithms. 22.1 Representations of graphs There are two standard ways to represent a graph G = (V, E): as a collection of adjacency lists or as an adjacency matrix. The adjacency-list representation of a graph G = (V, E) consists of an array Adj of |V| lists, one for each vertex in V. For each u∈V, the adjacency list Adj[u] contains (pointers to) all the vertices v such that there is an edge (u,v) ∈E. That is, Adj[u] consists of all the vertices adjacent to u in G. The vertices in each adjacency list are typically stored in an arbitrary order. For the adjacency-matrix representation of a graph G = (V, E), we assume that the vertices are numbered 1, 2, . . . , |V| in some arbitrary manner. The adjacency-matrix representation of a graph G then consists of a |V|×|V| matrix A = (aij) such that 22.2 Breadth-first search Breadth-first search is one of the simplest algorithms for searching a graph and the archetype for many important graph algorithms. Given a graph G = (V, E) and a distinguished source vertex s, breadth-first search systematically explores the edges of G to discover every vertex that is reachable from s. It computes the distance (fewest number of edges) from s to all such reachable vertices. It also produces a breadth-first tree with root s that contains all such reachable vertices. Breadth-first search is so named because it expands the frontier between discovered and undiscovered ve
原创力文档

文档评论(0)