Lecture 13

Algorithms

Distance Vector Algorithms

Tell your neighbours about the world

Tell directly connected neighbours about all your other neighbours/learned routes
Share distance (hops) and next-hop
Routes get updated when they have lower cost

Periodic vs triggered updates depends on the algorithm

Bellman-Ford

Preliminaries:

Steps:

Init:

Warning

There was an exam question on Bellman-Ford

Pasted image 20251014103457.png
Iteration 3 Node 5 can also be 10, based on if the nodes get updated left to right, or all at once
I.e. parallel or consecutive
If we do left to right, when node 5 is updated, the value of node 3 is already set to 5, making for a shorter path

Algorithm needs to run #nodes1 times, to make sure it has converged

Adding Memory

Nodes can store backup paths, instead of just the best
Fall back to them when the best link fails

However, this has some quirks
Backup path might use links from primary path, i.e. cause loops
Might be stale / no longer available
Also has slightly higher overhead

Count to Infinity

Even without memory, loops can be created:
Pasted image 20251014104036.png
Can be solved by (like in RIP):

Link State Algorithm

Dijkstra

Initialisation:

  1. Create a set sptSet (shortest path tree set) that keeps track of vertices included in the shortest path tree, i.e., whose minimum distance from the source is calculated and finalised. Initially, this set is empty.
  2. Assign a distance value to all vertices in the input graph. Initialize all distance values as INFINITE. Assign the distance value as 0 for the source vertex so that it is picked first
    Repeat steps:
  3. While sptSet doesn’t include all vertices:
    • Pick a neighbour vertex u that is not there in sptSet and has a minimum distance value (source -> u).
      • This will always be something adjacent to the current SPT, as anything else has distance
    • Include u to sptSet.
    • Then update the distance value of all adjacent vertices of u.
      • To update the distance values, iterate through all adjacent vertices.
      • For every adjacent vertex v, if the sum of the distance value of u (from source) and weight of edge <u,v> , is less than the distance value of v, then update the distance value of v
        • If the value is not lower, do not update
        • Considered greedy, as we always want the best distance

Pasted image 20251014104818.png

Warning

Exam might ask to execute Dijkstra, showing which nodes are included and the distances at each step

Shortest Path Tree (SPT)

Create a tree with the shortest path from a source node to all other nodes
Both Bellman-Ford and Dijkstra are SPT algorithms

Minimum Spanning Tree (MST)

A spanning tree is a tree-like subgraph that includes all vertices
A minimum spanning tree has all properties of a spanning tree, AND the sum of weights is minimal

There can be multiple (minimum) spanning trees per graph

Prim's and Kruskal's are MST algorithms

Algorithms based on Global or Centralised Information

Prim's Algorithm

Initialisation:

  1. Create a set mstSet that keeps track of vertices already included in MST.
  2. Assign a key value to all vertices in the input graph. Initialise all key values as INFINITE. Assign the key value as 0 for the first vertex so that it is picked first.
  3. While mstSet doesn’t include all vertices:
    > A.k.a. always pick the smallest edge already connected to your tree that doesn't form a loop
    • Pick a vertex u that is not there in mstSet and has a minimum key value.
    • Include u in the mstSet.
    • Update the key value of all adjacent vertices of u. To update the key values, iterate through all adjacent vertices:
      • For every adjacent vertex v, if the weight of edge u-v is less than the previous key value of v, update the key value as the weight of u-v.
        Pasted image 20251014112330.png

Simple:

  1. Start with a random node, add it to the MST
  2. Choose the edge with minimum value that spans between the MST and a node not in the MST
    • Update values of new MST node
  3. Repeat until all vertices are in MST

Kruskal's

  1. Sort all edges in non-decreasing order
  2. Pick the smallest edge that does not form a loop
  3. Repeat #2 until there are (V-1) edges in the spanning tree
    Pasted image 20251014112857.png

Key Takeaways

All tree algorithms create spanning trees
If all distances/weights are different, then there is a single/unique MST
If there is a unique MST, Kruskal can be parallelised

Not every MST is an spanning tree for all nodes
Not every SPT is automatically an MST
Pasted image 20251014113141.png|400

Exam

Topics:

Question types:

Allowed materials:

Commands, headers & fields will not be tested

Q1

  1. ARP is a broadcast, so 255.255.255.255?
    The IP it wants to know is 10.1.5.4
  2. The problem lies in the fact that the two networks have different subnet masks: /16 vs /24
    Therefore, H2 thinks S2 is in the subnet -> it should use ARP to address it directly
    However, S2 is in a different network, across a router
    The network S2 is in is /24, and does not consider H2 to be in the same subnet
    Therefore, the router would require special configuration to forward the ARP request anyway, or impersonate S2 and answer the ARP itself
    If the above are not used, the ping will not work

Q2

  1. Router 5 is not connected to area 0, so no it will not work
  2. One can switch area 2 and area 0
    Otherwise, use a virtual link that connects R4 to area 0

Q3

  1. VLANs, basically

Q4

  1. Run Dijkstra