Unit 5 Aads
Unit 5 Aads
► The Bellman-Ford algorithm is a graph algorithm used to find the shortest paths
from a single source vertex to all other vertices in a weighted graph. It can handle
graphs with negative-weight edges, unlike Dijkstra's algorithm.
Steps:
Sort all edges by their weights.
Initialize a forest where each vertex is its own tree.
Time Complexity:
Sorting edges: O(ElogE).
Union-Find operations: O(E α(V)), where α is the inverse Ackermann
function (very slow-growing).
The Union-Find (or Disjoint Set Union) data structure is used to efficiently manage and
merge sets of vertices while applying Kruskal’s Algorithm to find a Minimum Spanning
Tree (MST). It helps to check whether adding an edge creates a cycle and ensures the graph
remains acyclic.
Key Operations:
Find: Determines which set a particular element belongs to. This helps check if two
vertices are already connected.
Union: Merges two sets. This is used to connect two vertices by adding an edge to the
MST.
Optimizations:
Path Compression: Speeds up the Find operation by directly linking elements to their root.
Union by Rank/Size: Ensures smaller trees are attached under larger ones to keep the
structure shallow.