Chapter4算法概论概要1.pptVIP

  • 0
  • 0
  • 约6.36千字
  • 约 40页
  • 2017-07-02 发布于湖北
  • 举报
Chapter4算法概论概要1

4.6.1 Negative edges * In fact, terminate when no update occurs 4.6.1 Negative edges * 4.6.2 Negative cycles * Negative cycle: the length of cycle is negative The shortest-path problem is ill-posed in graphs with negative cycles. Use the Bellman-Ford algorithm to detect negative cycles After |V|-1 iterations, perform one extra round Negative cycle exists = some dist value is reduced during the extra round -4 4.7 Shortest paths in dags * In any path of a dag, the vertices appear in increasing linearized order. Linearize the dag by DFS, and visit the vertices in sorted order, updating the edges out of each. Find longest paths in a dag: negate all edge lengths. 4.7 Shortest paths in dags * O(|V|+|E|) Exercise 4.1 * Exercise 4.1 * Exercise 4.4 * Exercise 4.4 * Exercise 4.5 * Exercise 4.5 * Exercise 4.10 * Exercise 4.15 * Exercise 4.15 * HOMEWORK Textbook: Ex. 4.2,4.18 * * DESIGN AND ANALYSIS OF ALGORITHMS CHAPTER 4 Paths in graphs 4.1 Distances 4.2 Breadth-first search 4.3 Lengths on edges 4.4 Dijkstra’s algorithm 4.5 Priority queue implementations 4.6 Shortest paths in the presence of negative edges 4.7 Shortest paths in dags * * 4.1 Distances Distance between two nodes: the length of the shortest path between them. DFS identifies all the vertices which can be reached from a starting point, but cannot find shortest paths in graphs. * * 4.2 Breadth-first search * * 4.2 Breadth-first search * * 4.2 Breadth-first search Correctness For each d=0,1,2,…, there is a moment at which All nodes at distance ? d from s have their distances correctly set All other nodes have their distances set to ? The queue contains exactly the nodes at distance d Efficiency Each vertex is put on the queue exactly once, so there are 2|V| queue operations The innermost loop looks at each edge once (in directed graphs) or twice (in undirected graphs), so takes O(|E|) time The overall running time: O(|V| + |E|) * * 4.2 Breadth-first search DFS vs. BFS DFS makes deep incursions into graphs; BF

文档评论(0)

1亿VIP精品文档

相关文档