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

The Class LinkedDirectedGraph

 

 

 

 

 

The Class LinkedVertex

 

 

The Class LinkedEdge


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.

 

 

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读