Pseudo code

Let's take a look at the pseudo code for implementing Dijkstra's algorithm:

INITIALIZE Costs, Previous Paths, Visited Nodes

ADD each neighbor of start node to Previous Paths

GET cheapest node from start node and set as current node

WHILE node exists

GET cost of current node from costs

GET neighbors of current node

FOREACH neighbor

ADD cost of neighbor to current nodes cost as new cost

IF cost of neighbor not recorded OR cost of
neighbor is the lowest amongst all neighbors

SET cost of neighbor as new cost

SET the path of neighbor as current node


MARK current node as visited

GET cheapest node from start node and set as current node


INITIALIZE response

BACKTRACK path from end to start

RETURN distance and path