Author name: Mohammed Fahim

Minimum Spanning Tree in C++ Using Prim’s Algorithm with Priority Queue

A Minimum Spanning Tree (MST) is a subset of edges in a connected, weighted graph that connects all vertices without forming a cycle and with the minimum possible total edge weight. In this blog post, we implement Prim’s Algorithm using a min-heap (priority queue) to efficiently calculate the MST. Minimum Spanning Tree in C++ Using …

Minimum Spanning Tree in C++ Using Prim’s Algorithm with Priority Queue Read More »

Bellman-Ford Algorithm in C++ – Shortest Path with Negative Weights

The Bellman-Ford algorithm is a classical approach for finding the shortest path from a single source node to all other vertices in a weighted graph, even when the graph contains negative weight edges. Unlike Dijkstra’s algorithm, Bellman-Ford is capable of detecting negative weight cycles.In this post, we implement Bellman-Ford using a simple nested loop structure, …

Bellman-Ford Algorithm in C++ – Shortest Path with Negative Weights Read More »

Detecting Cycles in an Undirected Graph using BFS

Cycle detection in an undirected graph requires a slightly different approach. Since every edge connects both ways, we must carefully track visited nodes and their parents to avoid false positives. Detecting Cycles in an Undirected Graph using BFS  Idea Perform a BFS from every unvisited node (to handle disconnected graphs). If a visited node is …

Detecting Cycles in an Undirected Graph using BFS Read More »

Detecting Cycles in a Directed Graph using Kahn’s Algorithm (Topological Sort)

In graph theory, detecting cycles in a directed graph is a common problem with applications in scheduling, dependency resolution, and compiler design. One efficient way to solve this is using Kahn’s Algorithm, which is based on topological sorting. Detecting Cycles in a Directed Graph using Kahn’s Algorithm (Topological Sort)  Idea We count how many nodes …

Detecting Cycles in a Directed Graph using Kahn’s Algorithm (Topological Sort) Read More »

Scroll to Top