Graphs
Definition: Graph
A directed graph is a collection of vertices and edges that connect two vertices in a specific direction. Every edge has a non-negative weight associated with it, each vertex also has a non-negative weight associated with it.
Definition: Cost
The cost to go from one vertex to another one along a path of vertices is the sum of all the edge weights and the target vertex weights.
Theorem: Directed from Undirected Graph
If we have an undirected graph, we can map that onto directed graph by just duplicating all the edges, one for the forward and once for the backward direction.
Theorem: Vertex Weights into Edges
A graph with vertex weights can be converted into a graph with just edge weights by adding the vertex weight to all incoming edges.
Theorem: Dijksta's Algorithm
The optimal route between two vertices
- Create a heap of (distance, vertex) pairs which contains only the starting node
. - Create a mapping of vertex → distance which records the shortest distances found to each intermediate vertex, initialize with
. - Take the leading element
from the heap. Iterate through its edges . The edge will lead from vertex to vertex For each edge, compute the distance of the target vertex as . If that distance is smaller than the one already recorded, update it and add the pair to the heap. - Repeat until the distance to
is available.