You are on page 1of 44

Ad Hoc Networks:#

Architectures & Protocols

Dr Ljiljana Simić
iNETS, RWTH Aachen University
SS2016

Important  Note:  
These   course   notes   may   contain   some   copyrighted  
material.   The   copyright   of   this   material   covers   its  
use   in   class   and   for   educa7onal   purposes,   but   you  
are   not   allowed   to   distribute   this   course   material  
freely.   Under   the   code   of   appropriate   use,   please  
refrain   from   uploading   the   provided   source   files   or  
documents  to  any  publicly  accessible  system  outside  
RWTH  Aachen  University  without  prior  permission.  

1
– Graph Theory &#
Routing Fundamentals
#

Some Applications of Graph Theory


§  models  for  communica7ons  and  electrical  networks  
§  models  for  computer  architectures  
§  network  op7miza7on  models  for  opera7ons  analysis,  
including  scheduling  and  job  assignment  
§  analysis  of  Finite  State  Machines  
§  parsing  and  code  op7miza7on  in  compilers  

ver.ces  

edges  

2
Graphs ↔ Networks
Graph   Ver7ces   Edges  
Flow  
(Network)   (Nodes)   (Arcs)  
telephone  exchanges,   cables,  fiber  op.cs,  
voice,  video,  
communica.ons   computers,  satellites,   microwave/wireless  
data  packets  
radios   links  
gates,  registers,  processors  
circuits   wires   current  

mechanical   joints   rods,  beams,  springs   heat,  energy  

reservoirs,  pumping  
hydraulic   sta7ons,  lakes  
pipelines   fluid,  oil  

financial   stocks,  currency   transac7ons   money  

freight,  
airports,  rail  yards,  street   highways,  railbeds,  
transporta7on   intersec7ons   airway  routes  
vehicles,  
passengers    

Application to Ad Hoc Networking


§  networks  can  be  represented  by  graphs  
§  the  mobile  nodes  are  ver.ces  
§  the  wireless  communica7on  links  are  edges  

ver.ces  

edges  

§  rou7ng  protocols  oNen  use  shortest  path  algorithms  


§  this  lecture  is  background  material  for  ad  hoc  rou.ng  
algorithms    

3
Elementary concepts
ver.ces  
§  a  graph  G(V,E)  is  two  sets  of  objects  
-­‐      ver.ces  (or  nodes),  set  V  
-­‐  edges,  set  E  
  edges  
§  a  graph  is  represented  with  dots  or  circles  (ver7ces),  
joined  by  lines  (edges)  
 

§  the  magnitude  of  graph  G  is  characterized  by:  


-­‐  number  of  ver7ces  |V|  (called  the  order  of  G)  and  
-­‐  number  of  edges  |E|  (size  of  G)  
 

§  running  7me  of  algorithms  is  measured  in  terms  of  the  
order  &  size  

Directed graph
§  an  edge  e∈  E  of  a  directed  graph  is  represented  as  an  
ordered  pair  (u,v),  where:  
à u,  v  ∈  V  
à u  is  the  ini7al  vertex  and  v  is  the  terminal  vertex  
à assume  that  u  ≠  v  

2  

3  
1  

V  =  {  1,  2,  3,  4},  |V|  =  4  


4  
E  =  {(1,2),  (2,3),  (2,4),  (4,1),  (4,2)},  |E|=5  

4
Undirected graph
§  an  edge  e∈  E  of  an  undirected  graph  is  represented  as  an  
unordered  pair  (u,v)=(v,u),  where:  
à u,  v  ∈  V  
à assume  that  u  ≠  v  

2  

3  
1  

V  =  {  1,  2,  3,  4},  |V|  =  4  


4  
E  =  {(1,2),  (2,3),  (2,4),  (4,1)},  |E|=4  

Degree of a vertex
§  in  an  undirected  graph,  
degree  of  a  vertex  is  the  number  of  edges  incident  on  it  
§  in  a  directed  graph,  
à out  degree  of  a  vertex  is  the  number  of  edges  leaving  it  
à in  degree  of    a  vertex  is  the  number  of  edges  entering  it  
2 2

3 3
1 1

4 4

The  degree  of  vertex  4  is  2.     The  out  degree  of  vertex  4  is  2,    
the  in  degree  of  vertex    4  is  1.  

5
Weighted graph
§  a  weighted  graph  is  a  graph  for  which  each  edge  has  an  
associated  weight,  
usually  given  by  a  weight  func4on,  w:  E  →  R  

2 2
1.2   0.5   4   2  
6  
0.2   3 3
1 1
9  
2.1   8  
4 4

Walks and paths

3  
V2   V3  
1  
2  
3  
V1   1  
V6  
4  
4  
V4   V5  
1  

6
Walks and paths
§  a  walk  is  an  sequence  of  nodes  (v1,  v2,...,  vL)  such  that  
{(v1,  v2),  (v2,  v3),...,  (vL-­‐1,  vL)}  ⊆
     E,  e.g.  (V2,  V3,  V6,  V5,  V3)  
 

3  
V2   V3  
1  
2  
3  
V1   1  
V6  
4  
4  
V4   V5  
1  

Walks and paths


§  a  simple  path  is  a  walk  with  no  repeated  nodes,  
e.g.  (V1,  V4,  V5,  V2,  V3)  

3  
V2   V3  
1  
2  
3  
V1   1  
V6  
4  
4  
V4   V5  
1  

7
Walks and paths
 
§  a  cycle  is  a  walk  (v1,  v2,...,  vL)  where  v1=vL,  with  no  other  nodes  
repeated  and  L>3,  e.g.  (V1,  V2,  V5,  V4,  V1)  

§  a  graph  is  called  cyclic  if  it  contains  a  cycle;  


otherwise  it  is  called  acyclic  
 
3  
V2   V3  
1  
2  
3  
V1   1  
V6  
4  
4  
V4   V5  
1  

Complete graphs
§  a  complete  graph  is  an  undirected/directed  graph  in  which  
every  pair  of  ver7ces  is  adjacent  

§  if  (u,  v)  is  an  edge  in  a  graph  G,  


we  say  that  vertex  v  is  adjacent  to  vertex  u.  
 
A   B   A  
B  

C  

D   C  

§  4  nodes  and  (4*3)/2  edges   §  3  nodes  and  3*2  edges  
§  V  nodes  and  V*(V-­‐1)/2  edges       §  V  nodes  and  V*(V-­‐1)  edges  

8
Connected graphs
§  an  undirected  graph  is  connected  if  you   A B C
can  get  from  any  node  to  any  other  by  
following  a  sequence  of  edges  OR  any  
two  nodes  are  connected  by  a  path  
D E F

§  a  directed  graph  is  strongly  connected  if   A B

there  is  a  directed  path  from  any  node  


to  any  other  node  
C D

§  a  graph  is  sparse  if  |E|  ≈  |V|  


§  a  graph  is  dense  if    |E|  ≈    |V|2  

Bipartite graph
§  a  bipar4te  graph  is  an  undirected  graph  G=(V,E)  
in  which  V  can  be  par77oned  into  2  sets  V1  and  V2,  
such  that  (u,v)  ∈  E  implies  either:  
 u  ∈  V1  and  v  ∈  V2    
 or     V1   V2  
 v  ∈  V1    and  u  ∈  V2.  
u1  

  v1  
u2  

v2  
u3  
v3  

u4  

9
Trees

Trees
Let  G  =  (V,  E  )  be  an  undirected  graph.  
       à  the  following  statements  are  equivalent:   A  
 

1.   G  is  a  tree  


2.  any  two  ver.ces  in  G  are  connected  by  a      
B   C  
 unique  simple  path  
3.   G  is  connected,  but  if  any  edge  is  removed    
 from  E,  the  resul7ng  graph  is  disconnected  
4.   G  is  connected,  and    |E|  =  |V|  -­‐1   D   E  

5.     G  is  acyclic,  but  if  any  edge  is  added  to  E,      
 the  resul7ng  graph  contains  a  cycle  
6.   G  is  acyclic,  and    |E|  =  |V|  -­‐1   F  
 

10
Spanning Tree
§  a  tree  (T)  is  said  to  span  G  =  (V,E)  if  T  =  (V,E’)  and  E’    ⊆        E    

§  for  a  given  graph  there  are  usually   V2   V3  


several  possible  spanning  trees,  e.g.:    
 
V2   V3   V1  
V6  

V6   V4   V5  
V1  
T1  
V2   V3  

G V4   V5  
V6  
V1  

T2   V4  
V5  

Applications of Trees
§  unicast  rou7ng  (one-­‐to-­‐one)  →  shortest  path  spanning  tree  
§  mul7cast  rou7ng  (one-­‐to-­‐several)  
§  maximum  probability  of  reliable  one-­‐to-­‐all  communica7ons  
→  maximum-­‐weight  spanning  tree  
§  load  balancing  →  degree-­‐constrained  spanning  tree  

11
Minimum Spanning Tree
§  given  connected  graph  G  with  real-­‐valued  edge  weights  ce,  
a  Minimum  Spanning  Tree  (MST)  is  a  spanning  tree  of  G  
whose  sum  of  edge  weights  is  minimized  
  3  
2   24   3   2  
 4    4  
1   1  
23   9   9  
 6   18    6  
6   6  
 5   4    5   4  
 16   11   11  
 8   5    8   5  
7   7  
10      14  
7   21   8   7   8  

G  =  (V,  E)   T  =  (V,  F)   w(T)  =  50  


Cayley's  Formula  (1889)  
There  are  nn-­‐2  spanning  trees  of  a  complete  graph  Kn  
§  n  =  |V|,  m  =  |E|  
§  can't  solve  MST  by  brute  force  (because  of    nn-­‐2)  

Applications of MST
MST  is  central  combinatorial  problem  with  diverse  applica.ons  
§  designing  physical  networks  
§ telephone,  electrical,  hydraulic,  TV  cable,  computer,  road  
 

§  cluster  analysis  


§ delete  long  edges,  leaves  connected  components  
§ finding  clusters  of  quasars  and  Seyfert  galaxies  
§ analyzing  fungal  spore  spa7al  pakerns  
 

§  approximate  solu7ons  to  NP-­‐hard  problems  


§ metric  TSP  (Traveling  Salesman  Problem),  Steiner  tree  
 

§  indirect  applica7ons  


§ describing  arrangements  of  nuclei  in  skin  cells  for  cancer  research  
§ learning  salient  features  for  real-­‐7me  face  verifica7on  
§ modeling  locality  of  par7cle  interac7ons  in  turbulent  fluid  flow  
§ reducing  data  storage  in  sequencing  amino  acids  in  a  protein  
 

12
MST computation
Prim’s Algorithm
§ select  an  arbitrary  node  as  the  ini.al  tree  (T)  
§ augment  T  in  an  itera.ve  fashion  by  adding  the  outgoing  edge  
(u,v)  (i.e.  u  ∈  T  and  v  ∈  G-­‐T  )  with  minimum  cost  (i.e.  weight)  
§  the  algorithm  stops  aNer  |V|  -­‐  1  itera7ons  
§  computa7onal  complexity  =  O  (|V|2)  
 
Kruskal’s Algorithm
§ select  the  edge  e  ∈  E  of  minimum  weight  →  E’  =  {e}  
§ con7nue  to  add  the  edge  e  ∈  E  –  E’  of  minimum  weight  that  
when  added  to  E’,  does  not  form  a  cycle  
§  computa7onal  complexity  =  O  (|E|log|E|)  

Prim’s Algorithm (example)


V2   3   V3   V1  
V2   V3  
1   Algorithm  starts  
2   3  
3   V6   V2  
V1   1   1  
1  
4  
1   4   V1  
V1  
V4   V5  
ANer  the  1st  itera7on   ANer  the  2nd    itera7on  

V3   V3  
V2   3   V2   3   V2   3   V3  
1   1   1  
2  
1   1   1  
V1   V1  
V1   V6  
1   1  
V5   V4   V5   V4   V5  

ANer  the  3rd    itera7on   ANer  the  4th    itera7on   ANer  the  5th    itera7on  

13
Kruskal’s Algorithm (example)
V2   3   V2   V3  
V3   V2  
1  
1   1  
2   V1   Algorithm  
3   V6   starts   1  
V1   1   V1  
V2   V3   V4  
4   1  
1   4  
V4   V5   V1   1   V5  
ANer  the  1st   1  
itera7on   ANer  the  2nd    itera7on  
V5  

V2   V3   V2   3   V3  
1   1  
2   2  
1   1  
V1   V1  
V6   V6  
1   1  
V4   V5   V4   V5  
ANer  the  3rd    itera7on   ANer  the  4th    itera7on  

Distributed MST algorithms


§  each  node  does  not  need  complete  knowledge  of  the  topology  
§  MST  is  created  in  a  distributed  manner  
§  e.g.  GHS  algorithm  
 Gallager,  Humblet,  and  Spira,  “Distributed  Algorithm  for  Minimum-­‐Weight    
 Spanning  Trees,”  ACM  TransacRons  on  Programming  Languages  and  Systems,  
 January  1983,  pp.  66-­‐67.  
 

§  starts  with  one  or  more  fragments  consis7ng  of  single  nodes  
§  each  fragment  selects  its  minimum  weight  outgoing  edge  
§  using  control  messaging  fragments  coordinate  to  merge  with  a  
neighbouring  fragment  over  its  minimum  weight  outgoing  edge  
 

§  O(|V|log|V|)  7me,  provided  that  the  edge  weights  are  unique  
§  if  weights  not  unique,  algorithm  s7ll  works  by  using  the  nodes  IDs  to  break  7es  
between  edges  with  equal  weight  
§  requires  O(|V|log|V|)  +  |E|)  message  overhead    

14
Distributed MST (GHS) Algorithm (example)
V2   1   V3   V2   1   V3   Zero  level  
fragments  
1   2   3   4   1   2   3   4  
V6  
V7   5   5  
V1   V7  
4   5   V1   4   5   V6  
3   2   3   2  
V4   6   V5   V4   6   V5  

V2   1   1st    level   Nodes  3,  4,  and  


V3   fragments   V2   1   V3  
7  join  1st  level  
1   2   3   4   {1,2}  and   fragment  {1,2}   1   4  
2   3  
5   {5,6}  are  
V7   V7   5  
formed  
V1   4   5   V6   V6  
2   V1   4   5  
3   3   2  
V4   6   V5   V4   6   V5  

Fragments  {1,2,3,4,7}  and   V2   1   V3  


{5,6}  join  to  form  2nd  level  
1   2   3   4  
fragment  that  is  the  MST  
V7   5  

V1   4   5   V6  
3   2  
V4   6   V5  

Shortest Path Spanning Tree (SPST)


§  a  shortest  path  spanning  tree  T  is    
a  spanning  tree  rooted  at  a  par7cular  node,  such  that  the  
(|V|-­‐1)  minimum-­‐weight  paths  from  the  root  node  to  each  of  
the  other  network  nodes  is  contained  in  T  

2 2
2
2   6   2  
6   2  

3 1 3
1 5   3 1 5  

2   2  
2  
4 4
4
Shortest  Path  Spanning  Tree  
Graph   Minimum  Spanning  Tree   rooted  at  vertex  1  

§  note  that  SPST  is  not  the  same  as  the  MST  

15
Routing Applica7on  
§  main  func7on  of  the  Network  layer   Transport  
Network  
§  op.mality  principle:  
Data  Link  
“if  node  J  is  on  op7mal  path  IàK,  
   then  op7mal  path  JàK  is  along  same  route”   Physical  

§  set  of  op.mal  routes  from  all  sources  to  a  given  
des.na.on  form  a  sink  tree  rooted  at  the  des.na.on  
§  goal  of  all  rou7ng  algorithms  is  to  discover  and  use  the  
sink  trees  for  all  des7na7on  nodes  in  the  network  
2   24   3   2   24   3  
 4  
 
1  
23   9  
1    4  
23   9  
 6   18    6   18  
6   6   (shortest  path)  
 5   4    5   4  
 16  
5  
11    16   11   sink  tree  for  
 8    8   5  
 14  
7   7   des.na.on  
10     10      14  
node  3  
7   21   8   7   21   8  

Shortest path routing algorithms


§  assume  non-­‐nega7ve  edge  weights  
 

§  given  a  weighted  graph  (G,  W)  and  a  node  s,  


a  shortest  path  tree  rooted  at  s  is  a  tree  T  such  that,  
for  any  other  node  v  ∈  G,  the  path  between  s  and  v  in  T  
is  shortest  path  between  the  nodes  
 

§  examples  of  algorithms  which  compute  these  shortest  


path  trees  are  Dijkstra’s  and  Bellman-­‐Ford  algorithms,  
as  well  as  algorithms  which  find  the  shortest  path  
between  all  pairs  of  nodes,  e.g.  Floyd-­‐Warshall  

16
Dijkstra’s Algorithm
§  each  node  in  the  network  (graph)  is  labeled  with  its  
distance  from  the  source  node  along  the  best  known  path  
 

§  ini7ally  no  paths  are  known:  all  nodes  labeled  with  (∞,-­‐)  
§  as  algorithm  runs  and  paths  are  found,  labels  change  to  
reflect  beker  paths  
§  once  shortest  possible  path  from  source  to  a  node  is  found,  
its  label  changes  from  tenta4ve  to  permanent  

Dijkstra’s Algorithm (pseudocode)


%assume  s  to  be  the  root  (source)  node  
V’  =  {s};  U  =V-­‐{s};  E’  =  φ;    
for  v  ∈  U  do        
         Dv  =  w(s,v);  
       Pv  =  s;  
endFor  
while  U  ≠  φ  do  
       find  v  ∈  U    such  that  Dv  is  minimal;  
       V’  =  V’ ∪  {v};  U  =  U  –  {v};    
       E’  =  E’  ∪  (Pv,v);  
       for  x  ∈  U  do  
               if  Dv  +  w(v,x)  <  Dx  then    
                         Dx  =  Dv  +  w(v,x);  
                       Px  =  v;  
               endIf  
     endFor  
endWhile  

17
Dijkstra’s Algorithm (example)
1  
§  assume:   V2   V3  
     -­‐  V1  is  s  (source  node)   1   2   3   4  
     -­‐  Dv  =  distance  from  node  s  to  node  v     5  
V1   V7   V6  
§  if  there  is  no  edge  connec7ng  two   4   4  
nodes  x  and  y,  then  w(x,y)  =  ∞   3   2  

V4   6   V5  

Dijkstra’s Algorithm (example)


1  
§  1st  mark  source  node  V1  as  permanent       V2   V3  
1   2   3   4  
§  examine  all  nodes  adjacent  to  permanent  
5  
node,  re-­‐label  each  with:   V1   V7   V6  
     -­‐  its  distance  to  source  node   4   4  
     -­‐  &  the  permanent  node  from  which   3   2  
         examined  (reconstruct  final  path  later)   V4   6   V5  

V’  =  {1}  
(1,  V1)   1   (∞,  V1)  
V2   V3  
4  
1   2   3  
5  
V1   (∞,  V1)   V7   V6  
4   4   (∞,  V1)  
3  
2  
V4   6   V5  
(∞,  V1)  
(3,  V1)  

18
Dijkstra’s Algorithm (example)
1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2}  
(∞,  V1)  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
(∞,  V1)   5  
V1   (3,  V2)   V7   V6  
4   4   (∞,  V1)  
3  
2  
V4   6   V5  
(∞,  V1)  
(3,  V1)  

Dijkstra’s Algorithm (example)


1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2,3}  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
5  
V1   (3,  V2)   V7   V6  
4   4   (6,  V3)  
3  
2   (∞,  V1)  
V4   6   V5  
(∞,  V1)  
(3,  V1)  

19
Dijkstra’s Algorithm (example)
1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2,3,4}  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
5  
V1   (3,  V2)   V7   V6  
4   4   (6,  V3)  
3  
2  
V4   6   V5   (∞,  V1)  
(9,  V4)  
(3,  V1)  

Dijkstra’s Algorithm (example)


1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2,3,4,7}  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
5  
V1   (3,  V2)   V7   V6  
4   4   (6,  V3)  
3  
2  
V4   6   V5   (9,  V4)  
(7,  V7)  
(3,  V1)  

20
Dijkstra’s Algorithm (example)
1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2,3,4,7,6}  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
5  
V1   (3,  V2)   V7   V6  
4   4   (6,  V3)  
3  
2  
V4   6   V5  
(7,  V7)  
(3,  V1)  

Dijkstra’s Algorithm (example)


1  
§  find  temporary  node  with  smallest  label  in   V2   V3  
graph  and  make  it  permanent   1   2   3   4  
à  becomes  new  working  node   5  
V1   V7   V6  
§  examine  all  nodes  adjacent  to  working   4   4  
node,  relabel  if  path  to  source  node  via   3   2  
working  node  shorter   V4   6   V5  

§  REPEAT,  un7l  all  the  nodes  have  been  


processed  &  their  shortest  distance  to   V’  =  {1,2,3,4,7,6,5}  
source  has  been  computed     (1,  V1)   1   (2,  V2)  
V2   V3  
4  
1   2   3  
5  
V1   (3,  V2)   V7   V6  
4   4   (6,  V3)  
3  
2  
V4   6   V5  
(7,  V7)  
(3,  V1)  

21
Dijkstra’s Algorithm (example)
1  
§  note  that  the  tree  computed  is  a  shortest   V2   V3  
path  spanning  tree  rooted  at  V1,   1   2   3   4  
NOT  a  minimum  weight  spanning  tree   5  
V1   V7   V6  
(shown  below)  
4   4  
1   3   2  
V2   V3  
1   2   3   4   V4   6   V5  
5  
V1   V7   V6  

4   4  
3   2  
V4   6   V5  

Bellman-Ford Algorithm
§  find  the  shortest  walk  from  a  source  node  s  to  an  arbitrary  
des7na7on  node  v,  subject  to  the  constraints  that  the  walk  
consist  of  at  most  h  hops  and  goes  through  node  v  only  
once  

22
Bellman-Ford Algorithm (pseudocode)
 
%assume  s  to  be  the  root  (source)  node  
Dv-­‐1  =  ∞  ∀  v∈  V;  
Ds0  =  0  and  Dv0  =  ∞  ∀  v  ≠  s,  v  ∈  V  ;  
h  =  0;  
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
         h  =  h  +  1;  
         for  v∈  V  do    
                       Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
         endFor  
endUn.l  

Bellman-Ford Algorithm (example)


D20=∞   D30=∞  
1  
V2   V3  
4   D 0=∞
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
1   2   3   6            h  =  h  +  1;  
D10=0   5  
V1   D70=∞   V7   V6            for  v∈  V  do    
4   4                Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
3   2            endFor  
V5   D50=∞   endUn.l  
D40=∞   V4   6  

h=1   h=2   h=3   h=4  


D2h  
D3h  
D4h  
D5h  
D6h  
D7h  

23
Bellman-Ford Algorithm (example)
D2h-­‐1=∞   D3h-­‐1=∞  
1  
V2   V3  
4   D
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
1   2   3   6 =∞  
h-­‐1
         h  =  h  +  1;  
D1h-­‐1=0   5  
V1   D7h-­‐1=∞   V7   V6            for  v∈  V  do    
4   4                Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
3   2            endFor  
V5   D5h-­‐1=∞   endUn.l  
D4h-­‐1=∞   V4   6  

h=1   h=2   h=3   h=4  


D2h=1   D3h=∞  
D2h   1   1  
V3  
V2  
D3h   ∞   1   3   4   D h=∞
2   6  
D4h   3   D1h=0   5  
V1   D7h=∞   V   V6  
7
D5h   ∞   4   4  
3   2  
D6h   ∞  
V5   D5h=∞  
D7h   ∞   D4h=3   V4   6  

Bellman-Ford Algorithm (example)


D2h-­‐1=1   D3h-­‐1=∞  
1  
V2   V3  
4   D
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
1   2   3   6 =∞  
h-­‐1
         h  =  h  +  1;  
D1h-­‐1=0   5  
V1   D7h-­‐1=∞   V7   V6            for  v∈  V  do    
4   4                Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
3   2            endFor  
V5   D5h-­‐1=∞   endUn.l  
D4h-­‐1=3   V4   6  

h=1   h=2   h=3   h=4  


D2h=1   D3h=2  
D2h   1   1   1  
V3  
V2  
D3h   ∞   2   1   3   4   D h=∞
2   6  
D4h   3   3   D1h=0   5  
V1   D7h=3   V   V6  
7
D5h   ∞   9   4   4  
3   2  
D6h   ∞   ∞  
V5  
D7h   ∞   3   D4h=3   V4   6   D5h=9  

24
Bellman-Ford Algorithm (example)
D2h-­‐1=1   D3h-­‐1=2  
1  
V2   V3  
4   D
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
1   2   3   6 =∞  
h-­‐1
         h  =  h  +  1;  
D1h-­‐1=0   5  
V1   D7h-­‐1=3   V7   V6            for  v∈  V  do    
4   4                Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
3   2            endFor  
V5   D5h-­‐1=9   endUn.l  
D4h-­‐1=3   V4   6  

h=1   h=2   h=3   h=4  


D2h=1   D3h=2  
D2h   1   1   1   1  
V3  
V2  
D3h   ∞   2   2   1   3   4   D h=6
2   6  
D4h   3   3   3   D1h=0   5  
V1   D7h=3   V   V6  
7
D5h   ∞   9   7   4   4  
3   2  
D6h   ∞   ∞   6  
V5   D5h=7  
D7h   ∞   3   3   D4h=3   V4   6  

Bellman-Ford Algorithm (example)


D2h-­‐1=1   D3h-­‐1=2  
1  
V2   V3  
4   D
un.l  (Dvh  =  Dvh-­‐1  ∀  v∈  V  )  or  (h  =  |V|)  do  
1   2   3   6 =6  
h-­‐1
         h  =  h  +  1;  
D1h-­‐1=0   5  
V1   D7h-­‐1=3   V7   V6            for  v∈  V  do    
4   4                Dvh  =  min{Duh-­‐1  +  w(u,v)}  ∀  u∈  V;    
3   2            endFor  
V5   D5h-­‐1=7   endUn.l  
D4h-­‐1=3   V4   6  

h=1   h=2   h=3   h=4  


D2h=1   D3h=2  
D2h   1   1   1   1   1  
V3  
V2  
D3h   ∞   2   2   2   1   3   4   D h=6
2   6  
D4h   3   3   3   3   D1h=0   5  
V1   D7h=3   V   V6  
7
D5h   ∞   9   7   7   4   4  
3   2  
D6h   ∞   ∞   6   6  
V5  
D7h   ∞   3   3   3   D4h=3   V4   6   D5h=7  

25
Floyd-Warshall Algorithm
§  find  the  shortest  path  between  all  ordered  pairs  of  nodes  
(s,v),  {s,v}∈  V  
§  each  itera7on  yields  the  path  with  the  shortest  weight  
between  all  pairs  of  nodes  under  the  constraint  that  only  
nodes  {1,2,…n},  n  ∈  |V|,  can  be  used  as  intermediary  
nodes  on  the  computed  paths  
§  algorithm  completes  in  O(|V|3)  7me  

Floyd-Warshall Algorithm (pseudocode)


 
D  =  W;  %W  is  the  matrix  representa7on  of  the  edge  weights  
for  u  =  1  to  |V|  do    
         for  s  =  1  to  |V|  do    
                   for  v  =  1  to  |V|  do  
                                     Ds,v  =  min{Ds,v  ,  Ds,u+  Wu,v}  
                       endFor    
         endFor  
endFor  

26
Floyd-Warshall Algorithm (example)
V2   D  =  W  
2   for  u  =  1  to  |V  |  do    
2  
2  
8            for  s  =  1  to  |V  |  do    
6                      for  v  =  1  to  |V  |  do  
V1   V3  
1  
4                                        Ds,v  =  min{Ds,v  ,  Ds,u+  Wu,v}  
                       endFor    
4   3  
1            endFor  
3  
V4   1  
V5   endFor  
5  

V1   V2   V3   V4   V5  
" 0 2 4 ∞ 3 % V1  
$ '
$ 2 0 8 ∞ 1 ' V2  
D0 = $ 6 2 0 4 3 ' V3  
$ 1 ∞ ∞ 0 5 '
$ ' V4  
$# ∞ ∞ ∞ 1 0 '& V5  

Floyd-Warshall Algorithm (example)


V2   D  =  W  
2   for  u  =  1  to  |V  |  do    
2  
2  
8            for  s  =  1  to  |V  |  do    
6                      for  v  =  1  to  |V  |  do  
V1   V3  
1  
4                                        Ds,v  =  min{Ds,v  ,  Ds,u+  Wu,v}  
                       endFor    
4   3  
1            endFor  
3  
V4   1  
V5   endFor  
5  

V1   V2   V3   V4   V5   V1   V2   V3   V4   V5  
" 0 2 4 3 % V1   " % V1  
$

' 0 2 4 ∞ 3
$ '
$ 2 0 8 ∞ 1 ' V2   $ 2 0 8 ∞ 1 '
V2  

D0 = $ 6 2 0 4 3 ' V3   D1 = $ 6 2 0 4 3 ' V3  
$ 1 0 5 ' $ '
$
∞ ∞
' V4   1 3 5 0 4 V4  
$ '
$# ∞ ∞ ∞ 1 0 '& V5   $# ∞ ∞ ∞ 1 0 '& V5  

27
Floyd-Warshall Algorithm (example)
" % "
$
0 2 4 ∞ 3
' 0 2 4 8 3 %
$ '
$ 2 0 6 ∞ 1 ' $ 2 0 6 10 1 '
D2 = $ 4 2 0 4 3 ' D3 = $ 4 2 0 4 3 '
$ 1 3 5 0 4 ' $ 1 3 5 0 4 '
$ ' $ '
$# ∞ ∞ ∞ 1 0 '& $# ∞ ∞ ∞ 1 0 '
&

! ! $
0 2 4 8 3 $ #
0 2 4 4 3
&
# &
# 2 0 6 10 1 & # 2 0 6 2 1 &
D4 = # 4 2 0 4 3 & D5 = # 4 2 0 4 3 &
# 1 3 5 0 4 & # 1 3 5 0 4 &
# & # &
#" 2 4 6 1 0 & #" 2 4 6 1 0 &%
%

Distributed Asynchronous#
Shortest Path Algorithms
§  each  node  computes  the  path  with  the  shortest  weight  to  
every  network  node  
 
§  no  centralized  computa.on  
 
§  as  for  the  distributed  MST  algorithm  (GHS),  
control  messaging  is  required  for  distributed  computa7on  

§  asynchronous  means  here  that  there  is  no  requirement  of  
inter-­‐node  synchroniza.on  for  the  computa7on  performed  
at  each  node  or  the  exchange  of  messages  between  nodes    

28
Link-State vs. Distance Vector

Link-state routing

§  each  node  has  complete  network  picture  (topology,  link  costs)  

§  how  does  each  node  get  the  global  state?  


§  each  node  reliably  floods  informa7on  about  its  neighbours  to  every  
other  

§  each  node  independently  calculates  the  shortest  path  


from  itself  to  every  other  node:  
§  for  example  by  Dijkstra’s  algorithm  
 

§  in  summary:  each  node  has  global  knowledge  of  network  


topology  &  link  cost  info  à  independently  calculates  routes  
 

29
Distance vector routing
§  each  node  knows  the  links  to  its  neighbours  
§  does  NOT  flood  this  informa7on  to  the  whole  network  

§  each  node  has  provisional  “shortest  path”  


§  e.g.  node  A:  “I  can  get  to  node  B  with  cost  11  via  next  hop  node  D”  
 

§  nodes  exchange  this  informa.on  with  their  neighbours  


§  again  no  flooding  
 

§  nodes  update  their  idea  of  the  best  path  using  informa7on  from  
their  neighbours  

§  in  summary:  nodes  jointly  calculate  routes  by  itera.vely  


exchanging  with  neighbours  best-­‐known  routes  to  all  nodes  

Distributed Dijkstra Algorithm


§  no  need  to  change  the  algorithm  

§  each  node  periodically  floods  a  control  message  throughout  


the  network  containing  link  state  informa.on  
→  transmission  overhead  is  O(|V|x|E|)  

§  en.re  topology  knowledge  must  be  maintained  at  each  node  

§  flooding  of  the  link  state  informa7on  allows  for  7mely  
dissemina7on  of  the  topology  as  perceived  by  each  node  

§  each  node  typically  has  accurate  informa7on  to  be  able  to  
compute  the  shortest  paths  

30
Distributed Bellman-Ford Algorithm
§  assume  G  contains  only  cycles  of  non-­‐nega7ve  weight,  
if    (u,v)  ∈  E,  then  so  is  (v,u)  
 

§  the  update  equa7on  is    


 

Ds,v  =  minu∈N(s){w(s,u)  +  Du,v},  ∀v∈  V-­‐{s}  

§  N(s)  =  neighbours  of  s  →  ∀u∈  N(s),  (s,u)  ∈  E    


 

§  each  node  only  needs  to  know:    


§  weights  of  the  edges  that  are  incident  to  it  
§  the  iden7ty  of  all  the  network  nodes  
§  es.mates  (received  from  its  neighbours)  of  the  
distances  to  all  network  nodes  

Distributed Bellman-Ford Algorithm


§  each  node  s  transmits  to  its  neighbours  its  current  
distance  vector  Ds,V  
§  likewise  each  neighbor  node  u  ∈  N(s)  transmits  to  s  
its  distance  vector  Du,V  
§  node  s  updates  Ds,v,  ∀v  ∈  V  –  {s}  according  to  update  equa7on  
§  if  any  update  changes  a  distance  value,  then  s  sends  the  current  
version  of  Ds,v  to  its  neighbours    
§  node  s  updates  Ds,v    every  .me  that  it  receives  distance  vector  
informa.on  from  any  of  its  neighbors  
§  a  periodic  7mer  prompts  node  s  to  recompute  Ds,V  or  to  transmit  
a  copy  of  Ds,V  to  each  of  its  neighbours    

31
Distributed Bellman-Ford Algorithm (example)
1   C   Ini7al  Ds,V  
B  
7   s   A   B   C   D   E  
A   0   7   ∞   ∞   1  
A   8   2  
B   7   0   1   ∞   8  
1   C   ∞   1   0   2   ∞  

E   D   D   ∞   ∞   2   0   2  
2  
E   1   8   ∞   2   0  

Ds,V  
1  
B   C   A   B   C   D   E  
s  
7  
A   0   7   ∞   ∞   1  
A   8   2   B   7   0   1   ∞   8  
C   ∞   1   0   2   ∞  
1   D   ∞   ∞   2   0   2  
E   D   E   1   8   4   2   0  
2  
E  receives  D’s  routes  and  updates  its  Ds,V    

Distributed Bellman-Ford Algorithm (example)


A  receives  B’s  routes  and  updates  its  Ds,V    
Ds,V  
1  
B   C   A   B   C   D   E  
s  
7  
A   0   7   8   ∞   1  
A   8   2   B   7   0   1   ∞   8  
C   ∞   1   0   2   ∞  
1   D   ∞   ∞   2   0   2  
E   D   E   1   8   4   2   0  
2  
A  receives  E’s  routes  and  updates  its  Ds,V    
Ds,V  
1  
B   C   A   B   C   D   E  
s  
7  
A   0   7   5   3   1  
A   8   2   B   7   0   1   ∞   8  
C   ∞   1   0   2   ∞  
1   D   ∞   ∞   2   0   2  
E   D   E   1   8   4   2   0  
2  

32
Distributed Bellman-Ford Algorithm (example)
A’s  rou7ng  table  
1  
B   C  
Des7na7on   Next  Hop   Distance  
7  
B   B   7  
A   8   2   C   E   5  
D   E   3  
1  
E   E   1  
E   D  
2  
1   E’s  rou7ng  table  
B   C  
7   Des7na7on   Next  Hop   Distance  
A   A   1  
A   8   2   B   B   8  
C   D   4  
1  
D   D   2  
E   D  
2  

Distance Vector Protocols


§  each  node  maintains  a  rou.ng  table  with  entries  
{des.na.on,  next  hop,  distance  (cost)}  
 

§  nodes  exchange  rou.ng  table  informa.on  with  neighbors  


§  whenever  table  changes  
§  periodically  
 

§  upon  recep7on  of  a  rou7ng  table  from  a  neighbor,  


a  node  updates  its  rou.ng  table  if  finds  a  “beper”  route  
 

§  entries  in  the  rou.ng  table  are  deleted  if  they  are  too  old,  
i.e.  they    are  not  “refreshed”  within  certain  7me  interval  by  
the  recep7on  of  a  rou7ng  table  

33
Link Failure B  

E  
C  
A  

simple  rerou.ng  case   D  


§  F  detects  that  link  to  G  has  failed   F  
§  F  sets  a  distance  of  ∞  to  G  and  sends  update  to  A  
§  A  sets  a  distance  of  ∞  to  G  since  it  uses  F  to  reach  G   G  
§  A  receives  periodic  update  from  C  with  2-­‐hop  path  to  G  (via  D)  
§  A  sets  distance  to  G  to  3  and  sends  update  to  F  
§  F  decides  it  can  reach  G  in  4  hops  via  A  

Link Failure B  

E  
C  
A  

rou.ng  loop  case   D  


§  Link  from  A  to  E  fails   F  
§  A  adver7ses  distance  of  ∞  to  E  
§  B  and  C  had  adver.sed  a  distance  of  2  to  E   G  
(prior  to  the  link  failure)  
§  upon  recep.on  of  A’s  rou.ng  update  B  decides  it  can  reach  E  
in  3  hops;  and  adver.ses  this  to  A  
§  A  decides  it  can  read  E  in  4  hops;  adver7ses  this  to  C  
§  C  decides  that  it  can  reach  E  in  5  hops…  

this  behaviour  is  called  count-­‐to-­‐infinity  

34
Count-to-Infinity Problem
example:  routers  working  in  stable  state  

(A,1)   (A,2)   (A,3)   (A,4)  

A   B   C   D   E  
(A,1)   (A,2)   (A,3)  

rou7ng  updates  with  distances  to  A  shown  

Count-to-Infinity Problem
example:  link  from  A  to  B  fails  

(A,2)   (A,3)   (A,4)  

A   B   C   D   E  
(A,3)   (A,2)   (A,3)  

updated  informa7on  

B  can  no  longer  reach  A  directly,  


BUT  C  adver7ses  a  distance  of  2  to  A  
and  thus  B  now  believes  it  can  reach  A  via  C  and  adver.ses  it!  

35
Count-to-Infinity Problem
ANer    2  exchanges  of  updates  
(A,4)   (A,3)   (A,4)  

A   B   (A,3)   C   (A,4)   D   (A,3)   E  

ANer  3  exchanges  of  updates  


(A,4)   (A,5)   (A,4)  

A   B   (A,5)  
C   (A,4)  
D   (A,5)  
E  

ANer  4  exchanges  of  updates  


(A,6)   (A,5)   (A,6)  

A   B   (A,5)  
C   (A,6)  
D   (A,5)  
E  

Count-to-Infinity Problem
ANer  5  exchanges  of  updates  
(A,6)   (A,7)   (A,6)  

A   B   (A,7)  
C   (A,6)  
D   (A,7)  
E  

ANer  6  exchanges  of  updates  


(A,8)   (A,7)   (A,8)  

A   B   (A,7)   C   (A,8)   D   (A,7)   E  

this  con.nues  un.l  the  distance  to  A  reaches  infinity  


à  “bad  news  travels  slowly”  in  distance  vector  rou7ng!  

36
Split Horizon with Poisoned Reverse
§  algorithm  used  to  avoid  (not  always)  count-­‐to-­‐infinity  problem  
§  if  A  routes  to  C  via  B,  
then  A  tells  B  that  its  distance  to  C  is  ∞  

A   B   C  
(C,∞)  

B  will  not  route  to  C  via  A  if  the  link  B  to  C  fails  

§  works  for  two  node  loops  


§  does  not  work  for  loops  with  more  than  two  nodes  

Example where Split Horizon fails


§  when  link  C  to  D    breaks,  
C  marks  D  as  unreachable  and  reports  that  to  A  &  B  
§  suppose  A  learns  it  first   A   B  
§  A  now  thinks  best  path  to  D  is  through  B    
§  A  reports  D  unreachable  to  B  and  a  route  of  cost  3  to  C  
§  C  thinks  D  is  reachable  through  A  at  cost  4  and  reports  
that  to  B.   C  
§  B  reports  a  cost  5  to  A  who  reports  new  cost  to  C.  
§  etc...  

§  core  of  the  problem  is  that  when  X  tells  Y  that   D  
it  has  a  path  somewhere,  Y  has  no  way  of  knowing  
whether  it  is  itself  on  that  path!  

37
Graph Theory Addendum#
“The Stable Marriage Problem”

38
The Stable Marriage Problem

§  Problem:  Given  N  men  and  N   Men   Women  


women,  find  a  "suitable"  
matching  between  men  and  
women   Brek   Eve  

Mark   Ann  
§  the  problem  and  the  solu7on  
can  be  represented  as  a   John   Lisa  
bipar.te  graph  
Jack   Helen  

Bob   Marge  

The Stable Marriage Problem


§  graph  edges  represent  all  
possible  matching  
Men   Women  
§  matching  (M)  means  to  select  
some  of  the  edges  according  to  
Brek   Eve  
some  criteria  
§  perfect  matching:  each  man  gets   Mark   Ann  

exactly  one  woman;  each  


John   Lisa  
woman  gets  exactly  one  man  
Helen  
§  a  matching  is  unstable  if  there  is   Jack  

a  pair  who  like  each  other  more   Bob   Marge  


than  their  spouses  (they  can  
improve  their  situa7on  by  
dumping  spouses  and  eloping)  

39
The Stable Marriage Problem

Men   Women  

§  Gale-­‐Shapley  Theorem:    


a  stable  marriage  always   Brek   Eve  

possible,  found  in  O(n2)  7me.  


Mark   Ann  

John   Lisa  

Jack   Helen  

Bob   Marge  

Matchmaker, Make Me A Match!


Gale-­‐Shapley  Algorithm  
§  each  man  lists  women  in  order  of  preference  (from  best  to  worst)  
§  each  woman  lists  men  in  order  of  preference  

Men’s  Preference  List   Women’s  Preference  List  


Man   1st   2nd   3rd   4th   5th   Woman   1st   2nd   3rd   4th   5th  
Rick   Anne   Eva   Ina   Kate   Maria   Eva   Vlad   Rick   Sam   Ulrich   Tim  
Sam   Ina   Anne   Eva   Maria   Kate   Anne   Tim   Sam   Ulrich   Rick   Vlad  
Tim   Anne   Kate   Maria   Ina   Eva   Maria   Sam   Tim   Ulrich   Vlad   Rick  
Ulrich   Eva   Ina   Maria   Anne   Kate   Ina   Rick   Vlad   Ulrich   Tim   Sam  
Vlad   Anne   Ina   Eva   Kate   Maria   Kate   Ulrich   Sam   Vesa   Tim   Rick  

best   worst   best   worst  

40
Matchmaker, Make Me A Match!
Gale-­‐Shapley  Algorithm  
§  all  people  begin  unengaged  
§  while  there  are  unengaged  men,  each  proposes  un7l  a  woman  accepts  
§  unengaged  women  accept  1st    proposal  they  get  
§  if  an  engaged  woman  receives  a  proposal  she  likes  beper,  she  breaks  old  
engagement  and  accepts  new  proposal;  dumped  man  begins  proposing  
where  he  leN  off    
Men’s  Preference  List   Women’s  Preference  List  
Man   1st   2nd   3rd   4th   5th   Woman   1st   2nd   3rd   4th   5th  
Rick   Anne   Eva   Ina   Kate   Maria   Eva   Vlad   Rick   Sam   Ulrich   Tim  
Sam   Ina   Anne   Eva   Maria   Kate   Anne   Tim   Sam   Ulrich   Rick   Vlad  
Tim   Anne   Kate   Maria   Ina   Eva   Maria   Sam   Tim   Ulrich   Vlad   Rick  
Ulrich   Eva   Ina   Maria   Anne   Kate   Ina   Rick   Vlad   Ulrich   Tim   Sam  
Vlad   Anne   Ina   Eva   Kate   Maria   Kate   Ulrich   Sam   Vlad   Tim   Rick  

best   worst   best   worst  

Gale-Shapley Algorithm
Is  resul7ng  G-­‐S  matching  stable?  

Man   1st   2nd   3rd   Woman   1st   2nd   3rd  


perfect  matching  but  unstable,  
Tim   Eva   Anne   Maria   Eeva   Ulrich   Tim   Vlad  
since  (Anne,  Tarmo)  prefer  
Ulrich   Anne   Eva   Maria   Anne   Tim   Ulrich   Vlad   each  other  to  current  partners  
Vlad   Eva   Anne   Maria   Maria   Tim   Ulrich   Vlad  

Man   1st   2nd   3rd   Woman   1st   2nd   3rd  

Tim   Eeva   Anne   Maria   Eeva   Ulrich   Tim   Vlad   perfect  stable  matching  
(men  propose)  
Ulrich   Anne   Eeva   Maria   Anne   Tim   Ulrich   Vlad  

Vlad   Eeva   Anne   Maria   Maria   Tim   Ulrich   Vlad  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

41
Gale-Shapley Algorithm
Results  of  G-­‐S  algorithm  are  always  stable  
§  it  requires  two  people  of  opposite  sex  in  different  couples  to  break  up  
a  marriage  
§  if  a  man  wants  to  leave  for  another  woman,  then  he  already  proposed  
to  her  and  she  rejected  him,  so  she  won’t  leave  her  husband  for  him  

Man   1st   2nd   3rd   Woman   1st   2nd   3rd  


perfect  matching  but  unstable,  
Tim   Eva   Anne   Maria   Eeva   Ulrich   Tim   Vlad  
since  (Anne,  Tarmo)  prefer  
Ulrich   Anne   Eva   Maria   Anne   Tim   Ulrich   Vlad   each  other  to  current  partners  
Vlad   Eva   Anne   Maria   Maria   Tim   Ulrich   Vlad  

Man   1st   2nd   3rd   Woman   1st   2nd   3rd  

Tim   Eeva   Anne   Maria   Eeva   Ulrich   Tim   Vlad   perfect  stable  matching  
(men  propose)  
Ulrich   Anne   Eeva   Maria   Anne   Tim   Ulrich   Vlad  

Vlad   Eeva   Anne   Maria   Maria   Tim   Ulrich   Vlad  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

Gale-Shapley Algorithm
Results  of  G-­‐S  algorithm  are  always  stable  
§  it  requires  two  people  of  opposite  sex  in  different  couples  to  break  up  
a  marriage  
§  if  a  man  wants  to  leave  for  another  woman,  then  he  already  proposed  
to  her  and  she  rejected  him,  so  she  won’t  leave  her  husband  for  him  

Man   1st   2nd   3rd   Woman   1st   2nd   3rd  

Tim   Eeva   Anne   Maria   Eeva   Ulrich   Tim   Vlad   perfect  stable  matching  
(women  propose)  
Ulrich   Anne   Eeva   Maria   Anne   Tim   Ulrich   Vlad  

Vlad   Eeva   Anne   Maria   Maria   Tim   Ulrich   Vlad  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

42
Gale-Shapley Algorithm
What  happens  when  men  do  the  proposing?  
§  who  is  beker  off  –  men  or  women?  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

Gale-Shapley Algorithm
What  happens  when  men  do  the  proposing?  
§  each  man  has  the  best  partner  he  can  have  in  any  stable  marriage  
§  each  woman  has  the  worst  partner  she  can  have  in  any  stable  marriage  
 
§  note  that  G-­‐S  always  produces  same  stable  marriage  
i.e.  order  of  proposals  is  irrelevant  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

43
Gale-Shapley Algorithm
Moral  of  the  story  …  
§  historically,  men  propose  to  women  -­‐    why?    
§  guys:    propose  early  and  oNen  
§  single  ladies:    ask  out  the  guys!  

Reference:    The  Stable  Marriage  Problem:  Structure  and  Algorithms  (Founda7ons  of  Compu7ng)  by    
Dan  Gusfield  and  Robert  Irving,  MIT  Press,  1989.  

END: Graph Theory Addendum#


“The Stable Marriage Problem”

44

You might also like