COMP 2711H: Lecture 17

Date: 2024-10-09 14:52:53

Reviewed:

Topic / Chapter:

summary

❓Questions

Notes

Distance in Graphs
  • Distance

    • distance : minimum number of edges in -path
      • or: length of -path
    • eccentricity of :
      • i.e. maximum distance from
    • center of graph: s.t.
    • radius: maximum distance from center
    • diameter: maximum distance within the graph
  • Theorems on graphs

    • theorem: for any graph :
    • proof:
      • left inequality: trivial
      • It cannot be the case that
        • center has max distance to (one used for diameter)
        • and must be able to connect at distance at least
    • theorem: if a tree w/ 3 or more vertices:
      • no leaf can be a center
    • proof:
      • suppose a leaf and its parent
      • then for all
      • thus cannot have minimum eccentricity
    • theorem: let be tree. it has either 1 center or 2 neighboring centers
    • proof
      • base case:
        • 1 vertex: has 1 center
        • 2 vertices: has 2 neighboring center
      • (strong) induction: for nodes w/ vertices
        • we know that leaf cannot be center, thus we eliminate them
        • then, for all that's remaining,
          • thus center does not change in any case
        • as new tree has less vertices, it is true
          • or: after repetition, it leads to base case
Single-Source Shortest Paths
  • Single-source shortest paths

    • let input: graph with vertex
    • we want output: for all
    • solution 1: breath-first search
      • BFS: explores all vertices at distance 0 first
        • then 1, 2, and until all in CC are discovered
        • (max: rounds)
    • solution 2: path length calculation
      • let :
    • distance: can be expressed as smallest w/
      • : all neighbors of
  • Weighted graphs

    • for weighted graph w/
      • length of path :
    • and distance given by:
    • initial weight:
      • ,
      • : path not defined
    • for
  • Adjacency matrix representation

    • adjacency matrix :
      • if no -edge exists:
    • example
graph LR
    1((1))
    2((2))
    3((3))
    4((4))
    1--2---2
    1--1---3
    2--6---4
    3--0---4

  • : shortest walk with one edge from to
    • for steps:
      • 👨‍🏫 a 'modified' matrix multiplication
        • multiplication into addition
        • sum into
    • for there to be step walk from to :
      • must be step walk from to , and edge between to
  • new matrix multiplication
  • logically, we obtain
      • as any 100 step path: can be divided into two 50 step paths
  • finally, can be computed by:
    if t = 1:
        return A
    if t = 0:
        return I // only valid path: to itself
    if t is even:
        B = pow(A, t/2)
        return B × B
    if t is odd:
        B = pow(A, ⌊t/2⌋)
        return B × B × A
    
  • then distance can be computed by
    • w/ shortest walk on edges
  • to support shortest walk w/ at most edges
    • self-loops can be added to each vertex
    • in this case, we have:
      • any CC: must be connected in edges at least
      • : no. of vertices
Dijkstra's Algorithm
  • Dijkstra's Algorithm

    • Input: weighted graph and vertex
      • w/ non-negative edge weights
    • Output: distance for every vertex
    • intuition
      • check vertex
      • for all of its neighbors: update its weight
      • for a walk with minimum length (say: ):
        • shortest walk for two vertices are finalized
        • as all other alternatives: longer than
      • then, update weights for all of 's neighbors, repeat
    • rough pseudocode
      1. initialize distances: for all
      2. create a priority queue containing all vertices in
      3. while is not empty:
        1. extract vertex w/ minimum distance from
        2. for each neighbor of :
          1. if :
            1. update the priority of in
    • Dijkstra's algorithm: results in a spanning tree
      • prove that it is indeed shorted path
Matchings
  • Matchings

    • matching
      • s.t. no two edges in sharing an endpoint
      • not necessarily covering all vertices
    • example
graph LR
    1(( ))
    2(( ))
    3(( ))
    4(( ))
    5(( ))
    1-->2
    2--M-->1
    1-->4
    2-->3
    3--M-->4
    4-->3
    4-->5
graph LR
    1(( ))
    2(( ))
    3(( ))
    4(( ))
    1-->2
    2--M-->1
    2-->3
    3--M-->4
    4-->3
  • : maximum matching is
    • all maximum matching: maximal
      • not the other way around
    • example
graph LR
      1(( ))
      2(( ))
      3(( ))
      4(( ))
      1-->2
      2--M-->3
      3-->4
    - maximal (cannot add anymore), but not maximum
  • Alternating walks and augmenting paths

    • suppose: being a matching in
    • alternating -walk: defined at
      • walk that alternates between edges in the matching and edges in the set
      • 👨‍🎓 ~=changing group every turn?
    • augmenting walk/path: alternating path starting & ending in
    • augmenting edge: cant be used for expanding the matching
      • simply: swap the colors, within the alternating path
  • Theorem on maximum matchings [Berge]

    • theorem: a matching is maximum iff it does not contain an augmented path
    • proof:
      • if there is augmented -> not maximum: trivial
        • as stated above
      • not maximum -> augmented
        • let be a non-maximum matching
        • let be a maximum matching
        • let
          • s.t.
            • i.e.
          • and let : a graph
          • degree of : at most 2
            • i.e. one from , another from
        • previously: a graph w/ degree at most 2: made of cycles / paths
          • for a cycle (w/ every edge having degree 2)
            • it must be an even cycle
            • as and within it must alternate all the time
          • however, as , there must be a path
            • starting with and ending with
            • which is an augmented path for
          • if the matching was maximum: there won't be an augmented path