西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)07 Graph Algorithms

Definitions ■A graph G=(V,E)consists of a set of vertices,V and a set of edges,E. Each edge is a pair (v,w),where v,we V.Edges are sometimes referred to as arcs.If the pair is ordered,then the graph is directed. Vertex wis adjacent to v if and only if (v,w)eE. In an undirected graph with edge iv w,wis adjacent to vand vis adjacent to w.Some times an edge has a third component,known as either a weight or a cost
Definitions ◼ A graph G=(V, E) consists of a set of vertices, V, and a set of edges, E. ◼ Each edge is a pair (v, w), where v, wV. Edges are sometimes referred to as arcs. If the pair is ordered, then the graph is directed. ◼ Vertex w is adjacent to v if and only if (v, w)E. In an undirected graph with edge {v, w}, w is adjacent to v and v is adjacent to w. Some times an edge has a third component, known as either a weight or a cost

Definitions A path in a graph is a sequence of vertices wi,w2, w3,...,Ww such that (wi W1)EEfor 1s/N.The length of such a path is the number of edges on the path,which is equal to /1. ■ We allow a path from a vertex to itself;if this path contains no edges,then the path length is 0. If the graph contains an edge (v,v)from a vertex to itself,then the path v,vis sometime referred to as a loop.The graphs we will consider will generally be loopless. A simple path is a path such that all vertices are distinct,except that the first and the last could be the same
Definitions ◼ A path in a graph is a sequence of vertices w1 , w2 , w3 , …, wN such that (wi , wi+1)E for 1i<N. The length of such a path is the number of edges on the path, which is equal to N-1. ◼ We allow a path from a vertex to itself; if this path contains no edges, then the path length is 0. ◼ If the graph contains an edge (v, v) from a vertex to itself, then the path v, v is sometime referred to as a loop. The graphs we will consider will generally be loopless. ◼ A simple path is a path such that all vertices are distinct, except that the first and the last could be the same

Definitions A cycle in a directed graph is a path of length at least 1 such that wi=w;this cycle is simple if the path is simple. For undirected graphs,we require that the edges be distinct;that is,the path u,v,win an undirected graph should not be considered a cycle,because (u, v and (v,u)are the same edge.In a directed graph, these are different edges,so it makes sense to call this a cycle. A directed graph is acyclic if it has no cycles
Definitions ◼ A cycle in a directed graph is a path of length at least 1 such that w1=wn ; this cycle is simple if the path is simple. ◼ For undirected graphs, we require that the edges be distinct; that is, the path u, v, u in an undirected graph should not be considered a cycle, because (u, v) and (v, u) are the same edge. In a directed graph, these are different edges, so it makes sense to call this a cycle. ◼ A directed graph is acyclic if it has no cycles

Definitions An undirected graph is connected if there is a path from every vertex to every other vertex.A directed graph with this property is called strongly connected.If a directed graph is not strongly connected,but the underlying graph(without direction to the arcs)is connected,then the graph is said to be weakly connected. A complete graph is a graph in which there is an edge between every pair of vertices
Definitions ◼ An undirected graph is connected if there is a path from every vertex to every other vertex. A directed graph with this property is called strongly connected. If a directed graph is not strongly connected, but the underlying graph (without direction to the arcs) is connected, then the graph is said to be weakly connected. ◼ A complete graph is a graph in which there is an edge between every pair of vertices

Definitions In an undirected graph,the degree of a vertex is the number of edges connected to this vertex. In an directed graph,the outdegree of a vertex is the number of edges that start from this vertex,and the indegree is the number of edges that end at this vertex. ■ Examples of graphs:airport system,traffic flow, friendship
Definitions ◼ In an undirected graph, the degree of a vertex is the number of edges connected to this vertex. ◼ In an directed graph, the outdegree of a vertex is the number of edges that start from this vertex, and the indegree is the number of edges that end at this vertex. ◼ Examples of graphs: airport system, traffic flow, friendship

Representation of Graphs Suppose,for now,that we can number the vertices, starting at 1;that is,V1,2,...,n One simple way to represent a graph is to use a two- dimensional array this is known as a adjacency matrix representation. For each edge (u,we set A[u][]=1;otherwise the entry in the array is 0. a If the edge has a weight associated with it,then we can set Au][]equal to the weight and use either a very large or a very small weight as a sentinel to indicate nonexistent edges
Representation of Graphs ◼ Suppose, for now, that we can number the vertices, starting at 1; that is, V={1, 2, …, n} ◼ One simple way to represent a graph is to use a twodimensional array this is known as a adjacency matrix representation. ◼ For each edge (u, v), we set A[u][v]=1; otherwise the entry in the array is 0. ◼ If the edge has a weight associated with it, then we can set A[u][v] equal to the weight and use either a very large or a very small weight as a sentinel to indicate nonexistent edges

Representation of Graphs If the number of edges in a graph is very small,a better solution is an adjacency list representation. For each vertex,we keep a list of all adjacent vertices: The leftmost structure is merely an array of header cells.If the edges have weights,then this additional information is also stored in the cells
Representation of Graphs ◼ If the number of edges in a graph is very small, a better solution is an adjacency list representation. ◼ For each vertex, we keep a list of all adjacent vertices: The leftmost structure is merely an array of header cells. If the edges have weights, then this additional information is also stored in the cells

Topological Sort A topological sort is an ordering of vertices in a directed acyclic graph,such that if there is a path from vto v then vappears after v in the ordering. a See Figure 9.3:A directed edge (v,w)indicates that course vmust be completed before course wmay be attempted.A topological ordering of these courses is any course sequence that does not violate the prerequisite requirement
Topological Sort ◼ A topological sort is an ordering of vertices in a directed acyclic graph, such that if there is a path from vi to vj , then vj appears after vi in the ordering. ◼ See Figure 9.3: A directed edge (v, w) indicates that course v must be completed before course w may be attempted. A topological ordering of these courses is any course sequence that does not violate the prerequisite requirement

Topological Sort It is clear that a topological ordering is not possible if the graph has a cycle,since for two vertices vand w on the cycle,vprecedes wand wprecedes v. The ordering is not necessarily unique;any legal ordering will do. A simple algorithm to find a topological ordering is first to find any vertex with no incoming edges.We can then print this vertex,and remove it,along with this edge,from the graph.Then we apply this same strategy to the rest of the graph. Thus,we compute the indegrees of all vertices in the graph,and look for a vertex with indegree 0 that has not already been assigned a topological number
Topological Sort ◼ It is clear that a topological ordering is not possible if the graph has a cycle, since for two vertices v and w on the cycle, v precedes w and w precedes v. ◼ The ordering is not necessarily unique; any legal ordering will do. ◼ A simple algorithm to find a topological ordering is first to find any vertex with no incoming edges. We can then print this vertex, and remove it, along with this edge, from the graph. Then we apply this same strategy to the rest of the graph. ◼ Thus, we compute the indegrees of all vertices in the graph, and look for a vertex with indegree 0 that has not already been assigned a topological number

Topological Sort ■Example: 1 2 3 4 5 6 7
Topological Sort 3 1 6 2 7 5 ◼ Example: 4
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)06 Algorithm Analysis and Sorting.ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Iterative Improvement for Domain-Specific Problems(Chapter 16 Network Flow Chapter 17 Matching).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Coping with Hardness(Chapter 13 Backtracking Chapter 14 Randomized Algorithms Chapter 15 Approximation Algorithms).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)First-Cut Techniques(Chapter 8 The Greedy Approach Chapter 9 Graph Traversal).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Techniques Based on Recursion(Chapter 5 Induction Chapter 6 Divide and Conquer Chapter 7 Dynamic Programming).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Chapter 01 Basic Concepts in Algorithmic Analysis(主讲:刘静).ppt
- 《计算机基础》课程教学资源(参考论文)Motif Difficulty(MD):A Predictive Measure of Problem Difficulty for Evolutionary Algorithms using Network Motifs.pdf
- 《计算机基础》课程教学资源(参考论文)An Organizational Evolutionary Algorithm for Numerical Optimization.pdf
- 《计算机基础》课程教学资源(参考论文)A Multiagent Evolutionary Algorithm for Constraint Satisfaction Problems.pdf
- 《计算机基础》课程教学资源(参考论文)Comments on “the 1993 DIMACS Graph Coloring Challenge” and “Energy Function-Based Approaches to Graph Coloring”.pdf
- 《计算机基础》课程教学资源(参考论文)Moving Block Sequence and Organizational Evolutionary Algorithm for General Floorplanning with Arbitrarily Shaped Rectilinear Blocks.pdf
- 《计算机基础》课程教学资源(参考论文)A Multi-Agent Genetic Algorithm for Global Numerical Optimization.pdf
- 《计算机基础》课程教学资源(参考论文)An Organizational Coevolutionary Algorithm for Classification.pdf
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 12,14,15 Lecture_Computer Software(2/2).ppt
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 10-11 Lecture_Computer Software(1/2).ppt
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 1-5 Lecture_Computer Hardware(主讲:刘静).ppt
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 6-8 Lecture_Computer Codes.ppt
- 中国科学技术大学:《计算机网络 Computer Networks(计算机通信网)》课程教学资源(PPT课件讲稿,2022)Chapter 04 局域网与介质访问控制(卢汉成).pptx
- 中国科学技术大学:《计算机网络 Computer Networks(计算机通信网)》课程教学资源(PPT课件讲稿,2022)Chapter 03 数据链路层(卢汉成).pptx
- 中国科学技术大学:《计算机网络 Computer Networks(计算机通信网)》课程教学资源(PPT课件讲稿,2022)Chapter 02 物理层(卢汉成).pptx
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)08 Algorithm Design Techniques.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)03 Hashing.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)04 Priority Queues(Heaps).ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)05 Disjoint Set ADT.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)02 Trees(主讲:刘静).ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)01 Lists, Stacks, and Queues.ppt
- 中国科学技术大学:Robust Speech Recognition with Speech Enhanced Deep Neural Networks.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第九章 机器无关的优化.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第八章 代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第七章 运行时刻环境.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第六章 中间代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第五章 语法制导的翻译.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第四章 语法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第三章 词法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第一章 引论(许畅).pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)编译课程复习(许畅).pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验一 词法分析与语法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验二 语义分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验三 中间代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验四 目标代码生成.pdf