0% found this document useful (0 votes)
22 views40 pages

Lecture 7

This document provides an overview of graph theory concepts and the least-cost path problem. It discusses: - Representing communication networks as graphs with switches as vertices and lines as edges. Shortest path algorithms are used for routing. - Basic graph terminology like vertices, edges, adjacency, paths, cycles, and representations like the adjacency matrix. - Different graph types including directed, weighted, and trees. Minimum spanning trees and breadth-first search for finding them are covered. - Computing shortest path distances and lengths in weighted digraphs using Dijkstra's algorithm and the Bellman-Ford algorithm. Running times of graph algorithms are estimated.

Uploaded by

Abraham Gadissa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views40 pages

Lecture 7

This document provides an overview of graph theory concepts and the least-cost path problem. It discusses: - Representing communication networks as graphs with switches as vertices and lines as edges. Shortest path algorithms are used for routing. - Basic graph terminology like vertices, edges, adjacency, paths, cycles, and representations like the adjacency matrix. - Different graph types including directed, weighted, and trees. Minimum spanning trees and breadth-first search for finding them are covered. - Computing shortest path distances and lengths in weighted digraphs using Dijkstra's algorithm and the Bellman-Ford algorithm. Running times of graph algorithms are estimated.

Uploaded by

Abraham Gadissa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Lecture 7

Overview of Graph Theory and


Least-Cost Paths
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
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
• Example Graph Set V = {V1, V2, V3, V4, V5, V6}
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
• Adjacent Matrix Example
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 loops 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
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)
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
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
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)
Weighted Graph and Adjacent
Matrix
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
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
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
• E.g. Tree
Sub-graph
• Sub-graph 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’
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
Example
Example: Spanning Trees For
Previous Graph

• Also previous tree


example (slide 16)
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
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 V1 with 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 …
BFS of Previous Graph
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)
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|
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
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
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
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
Dijkstra’s Algorithm (2) –
Steps
1. Initialization
a. T = Tree = {s} - only source is so far
incorporated
b. L(n) = w(s, n) for n  s - initial path cost to
neighbors are link costs
2. Get next vertex
a. Find x  T such that L(x) = min L(j), j  T
b. Add x to T and Tree
c. Add edge to T incident on x and has least cost
• Last hop in path
3. Update least cost paths
a. 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
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
Dijkstra’s Algorithm on Example
Graph

Iteration T V2 v3 v4 v5 v6
1 {1} 2 5 1   v1
2 {1,4} 2 4 1 2  v4
3 {1,2,4} 2 4 1 2  v2
4 {1,2,4,5) 2 3 1 2 4 v5
5 {1,2,3, 4,5) 2 3 1 2 4 v3

6 {1,2,3, 4,5,6) 2 3 1 2 4 v6
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
Bellman-Ford Algorithm (2) –
Steps
1. Initialization
a. L0(n) =   n  s
b. Lh(s) = 0  h
2. Update
a. For each successive h  0
i. For each n  s, compute:
Lh+1+(n) = min[Lh(j)+ w(j,n)],  j
ii. Connect n with predecessor vertex j that achieves
minimum
iii. Eliminate any connection of n with different
predecessor vertex from previous iteration
iv. Path from s to n terminates with link from j to n
Bellman-Ford Algorithm (3) –
Notes
• Results agree with Dijkstra
• Running time order of |V| x |E|
Bellman-Ford Algorithm on
Example Graph
Results of Dijkstra and Bellman-
Ford
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 Bellman-Ford step 2
based on information from neighbors and
knowledge of link costs to update its costs and
paths
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
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

You might also like