Presentation on theme: "1 Dijkstra’s Minimum-Path Algorithm Minimum Spanning Tree CSE 30331 Lectures 20 – Intro to Graphs."— Presentation transcript:
1 Dijkstra’s Minimum-Path Algorithm Minimum Spanning Tree CSE 30331 Lectures 20 – Intro to Graphs
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
4 Minimum Spanning Tree Prim’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
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.