1 / 14

CSE 30331 Lectures 20 – Intro to Graphs

CSE 30331 Lectures 20 – Intro to Graphs. Dijkstra’s Minimum-Path Algorithm Minimum Spanning Tree. Minimum (weight) path – Dijkstra’s algorithm. Uses priority queue containing identities of all fringe vertices and the length of the minimum path to each from the start

sage-morris
Download Presentation

CSE 30331 Lectures 20 – Intro to Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 30331Lectures 20 – Intro to Graphs • Dijkstra’s Minimum-Path Algorithm • Minimum Spanning Tree

  2. Minimum (weight) path – Dijkstra’s algorithm • Uses priority queue containing identities of all fringe vertices and the length of the minimum path to each from the start • Algorithm builds a tree of all minimum length paths from start • Each vertex is either tree, fringe or unseen At each step The fringe vertex V with the minimum path is removed from priorityQ and added to the tree V’s non-tree neighbors U become fringe and the minimum path length is computed from start, thru V to U and is stored in U.dataValue, V is saved as U.parent and U is added to priorityQ • Process stops when queue is empty, or chosen destination vertex is found

  3. Dijkstra Minimum-Path Algorithm (Example A to D) PriQ: (A,0) Tree (vertices & path weight) (B,4) (C,11) (E,4) A,0 (E,4) (C,11) (C,10) (D,12) A,0 B,4 (C,10) (C,11) (D,12) A,0 B,4 E,4 (C,11) (D,12) A,0 B,4 E,4 C,10 (D,12) A,0 B,4 E,4 C,10 empty A,0 B,4 E,4 C,10 D,12

  4. Minimum Spanning TreePrim’s Algorithm • Spanning tree for graph with minimum TOTAL weight • Minimum Spanning Tree may not be unique, but total weight is same value for all • All vertices are either tree, fringe, or unseen • Priority queue is used to hold fringe vertices and the minimum weight edge connecting each to the tree Put start vertex in priorityQ While priorityQ not empty The nearest vertex V is removed from the queue and added to the tree For each non-tree neighbor U of V if the edge V,U weight < current U.dataValue U.dataValue is set to weight of edge V,U U.parent is set to V push U:weight pair onto priority queue

  5. Minimum Spanning Tree Example

  6. A A 2 12 2 B C 5 B 7 8 Spanning tree with vertices A, B D minSpanTreeSize = 2, minTreeWeight = 2 Minimum Spanning Tree: Step 1 (edge A-B)

  7. A A 2 2 12 5 B B C 5 7 8 D D Spanning tree with vertices A, B, D minSpanTreeSize = 3, minTreeWeight = 7 Minimum Spanning Tree:Step 2 (Edge A-D)

  8. A A 2 2 12 5 B B C 5 C 7 7 8 D D Spanning tree with vertices A, B, D, C minSpanTreeSize = 4, minTreeWeight = 14 Minimum Spanning Tree:Step 3 (Edge D-C)

  9. Runtime Orders of Complexity • Min Spanning Tree – O(V + E log2E) • Min Path (Dijkstra) – O(V + E log2E) • Strong Components – O(V + E) • Dfs – O(V+E) • BFS – O(V+E)

  10. Graphs – Important Terms • Vertex, edge, adjacency, path, cycle • Directed (digraph), undirected • Complete • Connected (strongly, weakly, components) • Searches (DFS, BFS) • Shortest Path, Minimum Path • Euler Path, Hamiltonian Path • Minimum Spanning Tree

  11. Searching Graphs • Breadth-First Search, bfs() • Locates all vertices reachable from a starting vertex • Uses a queue in process • Can be used to find the minimum distance from a starting vertex to an ending vertex in a graph.

  12. Searching Graphs • Depth-First Search, dfs() • Produces a list of all graph vertices in the reverse order of their finishing times. • Supported by a recursive depth-first visit function, dfsVisit() • An algorithm can check to see whether a graph is acyclic (has no cycles) and can perform a topological sort of a directed acyclic graph (DAG) • Forms the basis for an efficient algorithm that finds the strong components of a graph

  13. Searching Graphs • Dijkstra's algorithm (minimum path) • Uses a priority queue to determine a path from a starting to an ending vertex, of minimum weight • Prim's algorithm (minimum spanning tree) • An extension of Dijkstra’s algorithm, which computes the minimum spanning tree of an undirected, connected graph.

  14. Alaska Road Map • Assignment • File format • Demo

More Related