The Graph → The Python code to find the shortest path in the above ⬆️ graph → from collections import deque from typing import List, Tuple, Optional def bfs(n: int, graph: List[List[int]], source: int) -> Tuple[List[float], List[int]]: """ ...
Sharing some topic wise good Graph problems and sample solutions to observe on how to approach. Union Find: Identify if problems talks about finding groups or components. https://leetcode.com/problems/friend-circles/ https://leetcode.com/problems/...
The rhythm broke before the rule did. Not because something was missing — but because something repeated, when it shouldn’t have. The Shape That Shouldn’t Exist It was March 2025. A junior analyst at the European Anti-Fraud Office leaned forward....
When to Use BFS vs DFS Use BFS when: Shortest Path in Unweighted Graphs - BFS guarantees the shortest path because it explores nodes level by level Level-order Traversal - When you need to process nodes level by level Finding Minimum Steps - Any pro...
Reflecting on the Ant Colony Analogy: Traversing Graphs, Colony Style Over the past articles, we’ve embarked on an adventure through the world of graph theory with the help of our hardworking colony of ants. These tiny explorers taught us how to tack...
Introduction to Full Colony Exploration In an ant colony, paths are frequently traversed as ants carry out daily tasks, from food gathering to defending the Queen’s chamber. But what if an ant wanted to explore the entire colony, covering every singl...
Introduction to Flow Networks: Efficient Resource Flow in the Colony In an ant colony, efficient resource distribution is essential to ensure all ants receive the food they need. Imagine the colony as a complex network of chambers connected by tunnel...
Introduction to Bipartite Graphs: Splitting the Colony into Two Groups In the bustling world of an ant colony, there are times when the ants need to work in pairs, dividing tasks efficiently without conflicts. For instance, when splitting into two gr...
Introduction to Tarjan’s Algorithm: Optimizing Strongly Connected Component (SCC) Detection In a large, interconnected ant colony, identifying subcolonies quickly and efficiently is essential. As we explored with Kosaraju’s Algorithm, the ants could ...
Introduction to Strongly Connected Components (SCCs): Discovering Subcolonies In a large ant colony, some chambers form closely-knit sections where ants can travel freely between any pair of chambers without encountering dead ends or needing to backt...