Back to Practice Dashboard
DSA SectionEasy
Dijkstra
Learn how to solve the 'Dijkstra' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Given a weighted graph represented as an adjacency list, and a starting node, calculate the shortest distance from the starting node to all other nodes in the graph.
Constraints
- •1 <= V <= 1000
- •0 <= E <= 5000
- •Weights are non-negative.
Examples
Example 1
Input
graph = {0: {1: 4, 2: 1}, 1: {3: 1}, 2: {1: 2, 3: 5}, 3: {}}, start = 0Output
{0: 0, 1: 3, 2: 1, 3: 4}Need a Hint?
Represent graph node connections as an adjacency list/matrix, then use standard BFS or DFS graph traversal.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.