</>
ShikshaCSLearn. Code. Grow.
🔍
☕ Support Us
ShikshaCSâ€ēPractice Problems
DSAHardGraphs

Dijkstra's Shortest Path

📋 Problem

Given a weighted graph and a source node, find the shortest distance from the source to every other node.

🧭 Approach

Maintain a 'distance' array initialized to infinity (except the source, which is 0). Repeatedly pick the unvisited node with the smallest known distance, mark it visited, then 'relax' its neighbors — if going through this node gives a shorter path to a neighbor, update the neighbor's distance. A min-priority-queue makes picking the smallest efficient.

← Back to all Problems