Graph Theory37 sections · 1633 units
Open in Course

Dijkstra's Algorithm - Setup

Initialization and data structures

Before the main loop, you need to initialize two things:

1.1. Create a distance array dist[N] initialized to infinity (a large number like 101810^{18}). This tracks the shortest known distance to each node.

2.2. Set dist[start] = 0. The distance from the start to itself is zero.

3.3. Create a priority queue (min-heap) and push (0, start). The pair represents (distance, node).

dist := array of INF, size n
dist[start] := 0
pq := min-heap with (0, start)

Now you are ready for the main Dijkstra loop: repeatedly extract the minimum and relax neighbors.