Adjacency Matrix Graph¶
Source code: src/pydsadoc/_graph/adjacency_matrix.py
- class MGraph(num_vert: int, /)¶
Adjacency matrix graph.
- floyd_warshall() tuple[list[list[float]], list[list[float]]]¶
The Floyd-Warshall algorithm for finding shortest paths.
Time complexity is \(O(\vert V \vert ^3)\).
Floyd-Warshall Algorithm
The adjacency list for graph representation suits most algorithms except the Floyd-Warshall Algorithm. The Floyd-Warshall Algorithm is more efficient in a graph represented by an adjacency matrix.
Prim’s Algorithm
The key to the optimization of the Prim’s algorithm is the implementation of a
priority queue, such as the MinHeap in the
previous chapter, or the heapq in the python
standard library.
The algorithm is more efficient for dense graph. Also, it offers more flexibility when implemented with an adjacency list for graph representation. Combining with the priority queue and adjacency list, its time complexity can be optimized to \(O(\vert E \vert \log \vert V \vert)\).