Bellman-Ford Algorithm

Description

Prim’s algorithm is a well-known algorithm used for finding the minimum spanning tree in a weighted undirected graph. It is named after its inventor, Jarník and Prim, who independently developed it in 1930. Prim’s algorithm is a greedy algorithm that starts with a single vertex and adds one edge at a time to form a tree. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The process continues until all vertices are connected, and a minimum spanning tree is formed.

To implement Prim’s algorithm, the following steps are necessary:

Bellman-Ford Algorithm Diagram

Key Features

Use Case

In multicast or broadcast communication, sending messages to multiple VMs or tenants without redundancy is essential. OpenStack (via Neutron or SDN controllers) needs to minimize total network cost (latency, bandwidth, or hops).

OpenStack virtual networks form a graph with switches, routers, VMs, and links with weights (delay, bandwidth). Unlike Dijkstra (which finds shortest path from a single source), Prim’s algorithm builds a cost-efficient routing backbone (MST) that can connect multiple components with minimum overhead.

A set of users (or front-end gateways) need to be connected to a distributed set of VMs or compute nodes. You model this as a graph with weighted edges (cost of assigning a user to a VM: based on latency, load, or location).

Implementation

Below is the implimentation of leetcode solution for Min Cost to Connect All Points (Leetcode 1584).

Bellman-Ford Implementation in Java

References