1 / 35

Chapter 8, Part II

Chapter 8, Part II. Graph Algorithms. Minimum Spanning Tree. The minimum spanning tree (MST) of a weighted connected graph is a subgraph that contains all of the nodes of the original graph and a subset of the edges so that: The subgraph is connected

red
Download Presentation

Chapter 8, Part II

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. Chapter 8, Part II Graph Algorithms

  2. Minimum Spanning Tree • The minimum spanning tree (MST) of a weighted connected graph is a subgraph that contains all of the nodes of the original graph and a subset of the edges so that: • The subgraph is connected • The total weights of the subgraph edges is the smallest possible

  3. Brute Force Algorithm • We could look at each subset of the edge set and first see if it is connected and then see if its total weight is smaller than the best answer so far • If there are N edges in the graph, this process will require that we look at 2N different subsets • This is a lot more work than is needed

  4. The Dijkstra-Prim Method • This is a greedy algorithm that solves the larger problem by looking at a subset and making the best choice for it • In this case, we will look at all of the edges from the starting node and choose the smallest • On each pass, we will choose the smallest of the edges from nodes already in the MST to nodes not in the MST (the fringe)

  5. Dijkstra-Prim Example

  6. Dijkstra-Prim Example

  7. Dijkstra-Prim Example

  8. Dijkstra-Prim Example

  9. The Dijkstra-Prim Algorithm Select a starting node build the initial fringe from nodes connected to the starting node while there are nodes left do choose the edge to the fringe of the smallest weight add the associated node to the tree update the fringe by: adding nodes to the fringe connected to the new node updating the edges to the fringe so that they are the smallest end while

  10. The Kruskal Method • Kruskal’s algorithm concentrates on the edges instead of the nodes • First the edges are sorted in order of nondecreasing weight • Edges are added to the MST as long as they do not form a cycle with edges added in previous passes • When all of the nodes are connected and there are N – 1 edges in the MST, we are done

  11. Kruskal Example

  12. Kruskal Example

  13. Kruskal Example

  14. Kruskal Example

  15. The Kruskal Algorithm sort the edges in nondecreasing order by weight initialize partition structure edgeCount = 1 includedCount = 0 while edgeCount ≤ E and includedCount ≤ N-1 do parent1 = FindRoot(edge[edgeCount].start ) parent2 = FindRoot( edge[edgeCount].end ) if parent1 ≠ parent2 then add edge[edgeCount] to spanning tree includedCount = includedCount + 1 Union( parent1, parent2 ) end if edgeCount = edgeCount + 1 end while

  16. Shortest-Path Algorithm • The shortest-path algorithm finds the series of edges between two nodes that has the smallest total weight

  17. MST vs. Shortest Path • The MST algorithm can skip an edge of larger weight but include many edges of smaller weight that results in a longer path than the single edge

  18. Dijkstra’s Method • This is similar to the Dijkstra-Prim MST algorithm, but instead of just looking at the single shortest edge from a node to the fringe, we look at the shortest path from the start node to a fringe node

  19. Dijkstra’s Algorithm Select a starting node build the initial fringe from nodes connected to the starting node while we are not at the destination node do choose the fringe node with the shortest path to the starting node add that node and its edge to the tree update the fringe by: adding nodes to the fringe connected to the new node for each node in the fringe do update its edge to the one connected to the tree on the shortest path to the starting node end for end while

  20. Dijkstra’s Shortest-Path Example

  21. Dijkstra’s Shortest-Path Example

  22. Dijkstra’s Shortest-Path Example

  23. Dijkstra’s Shortest-Path Example

  24. Biconnected Components • A biconnected component of a graph is a set of nodes for which there is more than one path between each of the nodes • A biconnected component can also be just two nodes as well

  25. Biconnected Components Example • The following graph has three biconnected components:

  26. Articulation Points • An articulation point in a graph is a node that if removed would cause the graph to no longer be connected • Articulation points are the points where the graph can be broken down into its biconnected components

  27. Brute Force Method • Remove one node at a time and use a traversal method to see if the graph is still connected • If the graph is still connected, the removed node is not an articulation point • If the graph is no longer connected, the removed node is an articulation point

  28. A Better Method • If we do a depth-first traversal, when we reach a dead end, the adjacent visited nodes show us how far back in the graph we could go • This identifies the portion of the graph that has two different paths and is biconnected

  29. A Better Method • Keep a count of how many nodes have been visited and use this to assign an order number to each of the nodes • When we get to a dead end, we look at all of the order numbers for the adjacent nodes and pick the smallest one as the back index • We return the smallest back index to the previous node in the traversal

  30. A Better Method • When we get the back index values from each of the adjacent nodes we visited from the current node, we look at the smallest of these • If it is the same as or larger than the current node’s order number, we are at an articulation point and the nodes just visited are a biconnected component

  31. Partitioning a Set • We may need to have a set of numbers partitioned so that each number appears in exactly one subset • Programming language set data structures will not work because they cannot guarantee that each element will be in only one set • This partitioning ability is necessary for algorithms like Kruskal’s MST algorithm

  32. Partitioning Method • We have an array with one element for each of the set values • All of the array values are initialized with -1 to show that they are the root of a partition with just one element • As we combine partitions, we will replace these values with an ancestor in the combined partition and the root will have the total number of elements in the partition

  33. Partitioning Method Example

  34. Partitioning Sets Algorithms • Initialization: for i = 1 to N do Parent[i] = -1 end do • Union: // i, j the partitions to join together totalElements = Parent[i] + Parent[j] if Parent[i] ≥ Parent[j] then Parent[i] = j Parent[j] = totalElements else Parent[j] = i Parent[i] = totalElements end if

  35. Partitioning Sets Algorithms • Find Root: result = s while Parent[result] > 0 do result = Parent[result] end while return result

More Related