Dijkstra’s Algorithm — An Overview

Understand the Basics of Dijkstra’s Algorithm with examples in C, C++, Java, Python, and GOlang | Karthikeyan Nagaraj

Karthikeyan Nagaraj
7 min readFeb 20, 2023

--

What is Dijkstra’s Algorithm and How it Works?

  • Dijkstra’s Algorithm is a graph algorithm used to find the shortest path between two nodes in a weighted graph. A weighted graph is a graph in which each edge has a weight or cost.
  • Dijkstra’s Algorithm is a well-known algorithm in computer science that is used to solve the shortest path problem in a graph
  • This algorithm was developed by Edsger W. Dijkstra in 1956 and has been widely used ever since.
  • The algorithm uses a greedy approach to solve the problem.
  • It starts from the source node and considers the neighboring nodes, calculating the cost of reaching them from the source node.
  • The algorithm selects the node with the lowest cost and adds it to the list of visited nodes. The process continues until the destination node is reached.

Algorithm

  1. Create a set of unvisited nodes and set the distance of each node from the source node to infinity, except for the source node, which is set to zero.

--

--

Karthikeyan Nagaraj

Entrepreneur | Writer | Cyber Security Consultant | AI Researcher