重庆大学数据结构英文课件Graph_02

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

connected and without cycles.
Data Structure
05 Graph
Connectivity
graphs are connected if there is a path between any two vertices
Undirected
graphs are strongly connected if there is a path from any one vertex to any other
Directed
Data Structure
05 Graph
Connectivity
are weakly connected if there is a path between any two vertices, ignoring direction
Di-graphs
complete graph has an edge between every pair of vertices
Data Structure 05 Graph
Paths
v2, …, vn} such that (vi, vi+1) E for all 0 i < n.

A path is a list of vertices {v1,
Seattle Salt Lake City San Francisco
Data Structure
05 Graph
Depth-First Search (DFS)
Assume a particular node has been designated as the starting point. Let A be the last node visited and suppose A has neighbors N1,N2,…,Nk.
Anything
Data Structure
05 Graph
Trees as Graphs
Every
tree is a graph with some restrictions: the tree is directed there are no cycles (directed or undirected) B there is a directed path from the root to every node
access()
Data Structure
read()
05 Graph
Graph Traversals
A Graph Traversals, which is similar to a tree traversals in concept, is to visit every vertices of a graph exactly once in some specific order.
Data Structure
05 Graph (2)
College of Computer Science, CQU
Outline

Simple Path Connectivity Graph Traversals Topological Sorting
Data Structure
05 Graph
2 2 2
2.5
Salt Lake City
2.5
2.5
length(p) = 5 cost(p) = 11.5
San Francisco
Data Structure
3
Dallas
p = {SEA, SLC, CHI, DAL, SFO, SEA}
05 Graph
Simple Paths and Cycles
Data Structure 05 Graph
Connectivity
If there is a path from vertex vi to vj, vi and vj are connected.

An undirected graph are connected-----if, for every pair of distinct vertices vi , vj, there is a path from vi i to vj in G.

ห้องสมุดไป่ตู้
A depth-first search will: visit N1,then Proceed to traverse all the unvisited neighbors of N1 , then proceed to traverse the remaining neighbors of A in similar fashion
05 Graph
Data Structure
Data Structure
05 Graph
Connectivity

Acycle –a graph without cycles. directed acycle graph(DAG)--a directed graph without cycles. free tree—a connected, undirected graph with cycles. spanning tree—a subgraph of undirected graph G, which is

Data Structure
05 Graph
Graph Traversals
The
order in which the vertices are visited is important. There are two common traversals: Depth-first Breadth-first

Graph traversals begin with start vertex, and attempt to visit remaining vertices. There are two problems: If the graph is not connected, it may not be possible to reach all vertices. The graph may contains cycles, and a vertex may be reached more than one times.
A C E G I J
05 Graph
D
F H
Data Structure
Directed Acyclic Graphs (DAGs)

DAGs are directed graphs with no cycles Trees DAGs Graphs main()

mult() add()
1
Weighted Graphs
In a weighted graph, each edge has an associated weight or cost. 20 Clinton Kingston Bainbridge
60 30 35
Mukilteo
Edmonds Seattle
Bremerton

Data Structure
05 Graph
Implementing a DFS
Data Structure


Weakly connected(directed graph)---For a directed graph G, if Strongly connected Component---a maximal subgraph that is
strongly connected.
Degree of vi-----the number of edges incident to that vertex. In-degree---the number of edges that have vi as the head. out-degree---the number of edges that have vi as the tail. the number of edges: Where di is the degree of vertex vi
Chicago
Dallas
p = {SEA, SLC, CHI, DAL, SFO, SEA}
Data Structure
05 Graph
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

Connected component(undirected graph)----a maximal connected subgrap.( a tree is graph that is connected and acycle(无环))

distinct vertices vi , vj, there is a path from vi to vj ,and also from vj to vi in G.
Data Structure
05 Graph
Depth-First Search (DFS)
Data Structure
05 Graph
Depth-First Search (DFS)
Assume the node labeled a has been designated as the starting point, a depth-first traversal would visit the graph nodes in the order:
A
Data Structure
05 Graph
Graph Density
A
sparse graph has O(|V|) edges
A
dense graph has (|V|2) edges
in between is either sparsish or densy depending on the context.
Strongly connected(directed graph)--- if, for every pair of
Data Structure
05 Graph
Connectivity

the undirected graph obtained by suppressing the directions on the edges of G is connected.
A simple path repeats no vertices (except that the first can be the last):


p = {Seattle, Salt Lake City, San Francisco, Dallas} p = {Seattle, Salt Lake City, Dallas, San Francisco, Seattle}

A cycle is a path that starts and ends at the same node:

p = {Seattle, Salt Lake City, Dallas, San Francisco, Seattle}
A simple cycle is a cycle that repeats no vertices except that the first vertex is also the last (in undirected graphs, no edge can be repeated)

abecdfghi Note that if the edges taken during the depth-first traversal are marked, they define a tree (not necessarily binary) which includes all the nodes of the graph. Such a tree is a spanning tree for the graph. We call the tree DFS tree.
相关文档
最新文档