1 / 39

Understanding Graph Theory Basics and Paths

Learn about graph theory fundamentals, adjacent matrices, simple paths, digraphs, weighted graphs, trees, and subgraphs in this detailed overview. Ideal for grasping the essentials of graphs and paths.

brianj
Download Presentation

Understanding Graph Theory Basics and Paths

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 14 Overview of Graph Theory and Least-Cost Paths Chapter 14 Overview of Graph Theory and Least-Cost Paths

  2. Introduction • Comms networks can be represented by graphs • Switches & routers are vertices • Comms lines are edges • Routing protocols use shortest path algorithms • This chapter is background to chapters on routing Chapter 14 Overview of Graph Theory and Least-Cost Paths

  3. Elementary Concepts • Graph G(V,E) is two sets of objects • Vertices (or nodes) , set V • Edges, set E • Defined as an unordered pair of vertices • Shown as dots or circles (vertices) joined by lines (edges) • Vertex i is adjacent to vertex j if (i,j)  E • Magnitude of graph G characterised by number of vertices |V| (called the order of G) and number of edges |E|, size of G • Running time of algorithm measured in terms of order and size Chapter 14 Overview of Graph Theory and Least-Cost Paths

  4. Example Graph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  5. Adjacent Matrix • Used to represent graph • Number vertices • Arbitrary • 1,2,3,…,|V| • The |V| x |V| adjacent matrix A=(ai,j) defined by: • ai,j = 1 if (i,j)  E 0 otherwise • Matrix symmetrical about upper left to lower right diagonal • Because edge defined as unordered pair Chapter 14 Overview of Graph Theory and Least-Cost Paths

  6. Adjacent Matrix Example Chapter 14 Overview of Graph Theory and Least-Cost Paths

  7. Terminology • Two edges incident on same pair of vertices are parallel • Edge incident on single vertex is a loop • Graph with neither parallel edges nor loos is simple • Path from vertex i to vertex j is: • Alternating sequence of vertices and edge • Starting at i and ending at j • Each edge joins vertices immediately before and after it • Simple path – no vertex nor edge appears more than once • In simple graph, simple path may be defined by sequence of vertices • Each vertex adjacent to preceding and following vertices • No vertex repeated Chapter 14 Overview of Graph Theory and Least-Cost Paths

  8. Simple Paths (1) • From V1 to V6 (incomplete list) • V1,V2,V3,V4,V5,V6 • V1,V2,V3,V5,V6 • V1,V2,V3,V6 • V1,V2,V4,V3,V5,V6 • V1,V2,V4,V5,V6 • V1,V3,V2,V4,V5,V6 • V1,V3,V6 • V1,V4,V3,V6 • Total of 14 paths (Work out the rest yourself) Chapter 14 Overview of Graph Theory and Least-Cost Paths

  9. Simple Paths (2) • V1,V3,V6 is shortest • Distance between vertices is minimum number of edges on all paths • Cycle is path staring and ending on same vertex • E.g. V1,V3,V4,V1 Chapter 14 Overview of Graph Theory and Least-Cost Paths

  10. Digraphs • Directed graph • G(V,E) with each edge defined by ordered pair of vertices • Lines, representing edges, have arrow head to indicate direction • Parallel edges allowed if in opposite directions • Good for representing comms networks • Each directed edge represents data flow in one direction • Still use adjacent matrix • Not symmetrical unless each pair of adjacent vertices connected by parallel edges Chapter 14 Overview of Graph Theory and Least-Cost Paths

  11. Weighted Graph • Or weighted digraph • Number associated with each edge • Used to illustrate routing algorithms • Adjacent matrix defined as • ai,j =wi,j if (i,j)  E 0 otherwise Where wi,j is weight associated with edge (i,j) • Length of path is sum of weights • Shortest-distance path not necessarily shortest-length (see next two slides) Chapter 14 Overview of Graph Theory and Least-Cost Paths

  12. Weighted Graph and Adjacent Matrix Chapter 14 Overview of Graph Theory and Least-Cost Paths

  13. Path Distances and Lengths V1 to V6 Path Distance Length V1,V2,V3,V4,V5,V6 5 11 V1,V2,V3,V5,V6 4 8 V1,V2,V3,V6 3 10 V1,V2,V4,V3,V5,V6 5 10 V1,V2,V4,V5,V6 4 7 V1,V3,V2,V4,V5,V6 5 16 V1,V3,V6 2 10 V1,V4,V5,V6 3 4 Chapter 14 Overview of Graph Theory and Least-Cost Paths

  14. Trees • Subset of graphs • Equivalent definitions: • Simple graph such that if i and j vertices in T, there is a unique simple path from i to j • Simple graph of N vertices is tree if it has N-1 edges and no cycles • Simple graph of N vertices is tree if it has N-1 edges and is connected • One vertex may be designated root • Root drawn at top • Vertices adjacent to root drawn at next level • Can reach root on path distance 1 Chapter 14 Overview of Graph Theory and Least-Cost Paths

  15. Family Tree • Each vertex (except root) has one parent vertex • Adjacent vertex closer to root • Each vertex has zero or more child vertices • Adjacent vertices further from root • Vertex without children is called a leaf • Root assigned level 1 • Vertices immediately under root level 1 • Children of vertices on level 1 are on level 2 Chapter 14 Overview of Graph Theory and Least-Cost Paths

  16. E.g. Tree Chapter 14 Overview of Graph Theory and Least-Cost Paths

  17. Subgraph • Subgraph of graph G obtained by selecting number of edges and vertices from G • For each edge, the two vertices incident on that edge must be selected • Give graph G(E,V), graph G’(E’,V’) is a subgraph of G iff • V’  V and E’  E and •  e’  E’, if e’ incident on v’ and w’ then v’, w’  V’ Chapter 14 Overview of Graph Theory and Least-Cost Paths

  18. Spanning Tree • Subgraph T of graph G is a spanning tree if • T is a tree • T includes all vertices of G • In other words remove edges from G such that: • Remove all cycles • Maintain connectivity • Not usually unique Chapter 14 Overview of Graph Theory and Least-Cost Paths

  19. E.g. Spanning Trees For Previous Graph • Also previous tree example (slide 16) Chapter 14 Overview of Graph Theory and Least-Cost Paths

  20. Breadth First Search (BFS) for Spanning Tree • Partition vertices of graph into sets at various levels • Process all vertices on given level before proceeding to next level • Start at any vertex, x • Assign it level 0 • All adjacent vertices are at level 1 • Let Vi1, Vi2,Vi3,…Vij,be vertices at level i • Consider all vertices adjacent Vi1 not at level 1,2,…,i • Assign these level (i+1) • Consider all vertices adjacent Vi2 not at level 1,2,3,…,i, (i+1) • Assign these also level (i+1) • Until all vertices processed Chapter 14 Overview of Graph Theory and Least-Cost Paths

  21. E.g. Using Previous Graph • Choose order • Obvious one is V1,V2,V3,V4,V5,V6 • Select root • Again, obvious one is V1 • Let tree T consist of single vertex V1with no edges • Add to T each edge (V1,x) and vertex x • Such that no cycle is produced • Gives edges (V1,V2), (V1,V3), (V1,V4) and vertices V1,V2, V3 • This is first level • Repeat for all level 1 vertices to give level 2 • All vertices now added • If not repeat for level 2 to give level 3 … Chapter 14 Overview of Graph Theory and Least-Cost Paths

  22. BFS of Previous Graph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  23. Shortest Path Distance • BFS finds shortest path distance from given source vertex to all other vertices • Minimum number of edges in any path from s to v, δ(s,v) Chapter 14 Overview of Graph Theory and Least-Cost Paths

  24. Estimated Running Time • After initialization each vertex is used exactly once as a starting point for adding the next layer • Time take is order of |V| • Each edge already in tree is rejected if examined again • Each edge not in tree is checked to see if it produces a cycle • If not it is included • Bulk of edge processing is once per edge • Time take is order of |E| • Total time taken is linear with |V| and |E| Chapter 14 Overview of Graph Theory and Least-Cost Paths

  25. Shorted Path Length Determination • Packet switching, frame relay or ATM network can be viewed as digraph • Each node is a vertex • Each link is a pair of parallel edges • For an internet (Internet or intranet) • Each router is vertex • If routers directly connected (e.g. LAN or WAN) two way connection corresponds to pair of parallel edges • If more than two routers, network represented by multiple pairs of parallel edges • One pair connecting each pair of routers • In both cases, routing decision needed to pass packet from source to destination • Equivalent to finding path through a graph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  26. Routing Decisions • Based on least cost • Minimum number of hops • Each edge (hop) has weight 1 • Corresponds to minimum path distance • Or, cost associated with each hop (next slide) • Cost of path is sum of costs of links in path • Want least cost path • Corresponds to minimum path length in weighted digraph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  27. Cost of a Hop • Inversely proportional to path capacity • Proportional to current load • Monetary cost of link etc. • Combination • May be different in different directions Chapter 14 Overview of Graph Theory and Least-Cost Paths

  28. Dijkstra’s Algorithm (1) –Definitions • N = set of vertices in network • s = source vertex (starting point) • T = set of vertices so far incorporated • Tree = spanning tree for vertices in T including edges on least-cost path from s to each vertex in T • w(i,j) = link cost from vertex i to vertex j • w(i,i) = 0 • w(i,j) =  if i, j not directly connected by a single edge • w(i,j)  0 of i,j directly connected by single edge • L(n) = cost of least cost path from s to n currently known • At termination, this is least cost path from s to n Chapter 14 Overview of Graph Theory and Least-Cost Paths

  29. Dijkstra’s Algorithm (2) –Steps • Initialization • T = Tree = {s} - only source is so far incorporated • L(n) = w(s,n) for n  s - initial path cost to neighbors are link costs • Get next vertex • Find x  T such that L(x) = min L(j), j  T • Add x to T and Tree • Add edge to T incident on x and has least cost • Last hop in path • Update least cost paths • L(n) = min[L(n), L(x) + w(x,n)]  n  T • If latter term is minimum, path from s to n is now path from s to x concatenated with edge from x to n Chapter 14 Overview of Graph Theory and Least-Cost Paths

  30. Dijkstra’s Algorithm (3) –Notes • Terminate when all vertices added to T • Requires |V| iterations • At termination • L(x) associated with each vertex is cost of least cost path from s to x • Tree is a spanning tree • Defines least cost path from s to each other vertex • One step adds one vertex to T and defines least cost path from s to that vertex • Running time order of |V|2 Chapter 14 Overview of Graph Theory and Least-Cost Paths

  31. Dijkstra’s Algorithm on Example Graph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  32. Bellman-Ford Algorithm (1) –Definitions • s = source vertex (starting point) • w(i,j) = link cost from vertex i to vertex j • w(i,i) = 0 • w(i,j) =  if i, j not directly connected by a single edge • w(i,j)  0 of i,j directly connected by single edge • h = max number of links in path at current stage • Lh(n) = cost of least cost path from s to n such that no more than h links Chapter 14 Overview of Graph Theory and Least-Cost Paths

  33. Bellman-Ford Algorithm (2) –Steps • Initialization • L0(n) =   n  s • Lh(s) = 0  h • Update • For each successive h  0 • For each n  s, compute: Lh+1+(n) = min[Lh(j)+ w(j,n)],  j • Connect n with predecessor vertex j that achieves minimum • Eliminate any connection of n with different predecessor vertex from previous iteration • Path from s to n terminates with link from j to n Chapter 14 Overview of Graph Theory and Least-Cost Paths

  34. Bellman-Ford Algorithm (3) –Notes • Results agree with Dijkstra • Running time order of |V| x |E| Chapter 14 Overview of Graph Theory and Least-Cost Paths

  35. Bellman-Ford Algorithm on Example Graph Chapter 14 Overview of Graph Theory and Least-Cost Paths

  36. Results of Dijkstra and Bellman-Ford Chapter 14 Overview of Graph Theory and Least-Cost Paths

  37. Comparison of Information Needed – Bellman-Ford • Calculation for vertex n involves knowledge of link cost to all neighbors of n plus total path cost to each from source • Each vertex can keep set of costs and paths for every other vertex in network • Exchange information with direct neighbors • Each vertex can use use Bellman-Ford step 2 based on information from neighbors and knowledge of link costs to update its costs and paths Chapter 14 Overview of Graph Theory and Least-Cost Paths

  38. Comparison of Information Needed – Dijkstra • Step 3 requires each vertex must have complete topology • Must know link costs of all links in network • Information must be exchanged between all other vertices • Evaluation must also consider calculation time Chapter 14 Overview of Graph Theory and Least-Cost Paths

  39. Other Notes • Both Algorithms converge under static conditions of topology and link cost • Give to same solution • If link costs change, algorithms will attempt to catch up • If link costs depend on traffic, which depends on routes chosen: • Feedback condition exists • Instability may result Chapter 14 Overview of Graph Theory and Least-Cost Paths

More Related