# Data structures - Graphs 2

THE SHORTEST-PATH PROBLEM

The single-source paths problem asks for a solution that contains the shortest path from a given vertex to all the other vertices.

The all-pairs shortest path problem, asks for the set of all the shortest paths in a graph.

Dijkstra's Algorithm

Dijkstra's Algorithm solves the single-source paths problem.

The algorithm consists of two major steps: an initialization step and a computation step

The Initialization Step

The Computation Step

Floyd's Algorithm
Floyd's algorithm solves the all-pairs shortest paths problem.

SOME EXERCISES FOR DEVELOPING A GRAPH COLLECTION

SUMMARY

1、A graph consists of one or more vertices (items) connected by one or more edges.  One vertex is adjacent to another vertex if there is an edge connecting the two vertices. These two vertices are also called neighbors. A path is a sequence of edges that allows one vertex to be reached from another vertex in the graph. A vertex is reachable from another vertex if and only if there is a path between the two. The length of a path is the number of edges in the path. A graph is connected if there is a path from each vertex to every other vertex. A graph is complete if there is an edge from each vertex to every other vertex.

2、A subgraph consists of a subset of a graph's vertices and a subset of its edges. A connected component is a subgraph consisting of the set of vertices that are reachable from a given vertex.

3、.Directed graphs allow travel along an edge in just one direction, whereas undirected graphs allow two-way travel. Edges can be labeled with weights, which indicate the cost of traveling along them.

4、Graphs have two common implementations. An adjacency matrix implementation of a graph with N vertices uses a two-dimensional grid G with N rows and N columns. The cell G[i][j] contains 1 if there is an edge from vertex i to vertex j in the graph. Otherwise, there is no edge, and that cell contains 0. This implementation wastes memory if not all the vertices are connected.

5、An adjacency list implementation of a graph with N vertices uses an array of N linked lists. The ith linked list contains a node for vertex j if and only if there is an edge from vertex i to vertex j.

6、Graph traversals explore tree-like structures within a graph, starting with a distinguished start vertex. A depth-first traversal visits all the descendants on a given path first, whereas a breadth-first traversal visits all the children of each vertex first.

7、.A spanning tree has the fewest number of edges possible and still retains a connection between all the vertices in a graph. A minimum spanning tree is a spanning tree whose edges contain the minimum weights possible.

8、A topological sort generates a sequence of vertices in a directed acyclic graph.

9、The single-source shortest path problem asks for a solution that contains the shortest paths from a given vertex to all the other vertices.

05-03 5130

05-19 11

01-23 463

03-01 16

07-15 521

05-23 9

06-13 90

04-10 11

02-23 4164

05-19 33

05-19 9

03-02 1167

07-19 581

10-04 1110

07-03 667

08-31 674

04-09 8

04-24 14

04-03 7

12-10 379

08-02 307

05-03 37

11-20 414

04-14 56万+

03-13 14万+

02-27 7万+

02-28 4万+

03-01 12万+

03-01 11万+

03-01 1万+

03-03 2万+

05-23 4012

03-04 12万+

03-04 3394

03-05 5万+

03-08 4万+

03-08 6万+

03-08 2万+

03-08 1万+

04-25 6万+

03-10 12万+

03-10 17万+

03-12 10万+

03-13 10万+

03-19 7万+

03-22 3万+

03-23 1万+

03-23 4万+

03-24 3万+

03-25 2万+

05-08 4万+

03-25 8万+

03-26 3万+

03-27 4万+

03-29 20万+

03-29 9万+

03-30 14万+

05-21 2931

05-25 5225

03-23 1万+

04-02 3万+

05-06 2万+

04-05 1万+

04-06 898

04-06 6万+

04-07 4万+

04-09 7万+

04-09 2万+

05-17 5339

04-09 4720

04-11 2万+

04-15 5万+

04-18 4万+

04-20 3万+

04-24 2万+

04-26 3678

04-30 7534

05-16 4万+

05-06 1万+

#### 汉字不能编程？别闹了，只是看着有点豪横！容易被开除！

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客