Ananyasingh2002 / Hacktoberfest2023

Join Hacktoberfest 2023: Contribute to open source, learn, and earn rewards. Beginner-friendly. Explore issues, fork, code, and make a global impact. Let's collaborate!
https://ananyasingh2002.github.io/Hacktoberfest2023/
145 stars 1.22k forks source link

Dijkstra's_algorithm #765

Open Devika-H opened 1 year ago

Devika-H commented 1 year ago
  1. This C++ code implements Dijkstra's algorithm to find the shortest paths in a weighted graph. It uses a Graph class to manage the graph and a min-priority queue for efficient vertex selection.

  2. The addEdge method adds edges to the graph, allowing you to specify vertices and their corresponding edge weights.

  3. In the dijkstra method, the code initializes distances from the source vertex and uses a priority queue to explore vertices with the shortest distances first. It updates the distances and keeps track of the shortest path tree.

  4. The printSolution method is used to display the shortest distances from the source vertex to all other vertices.

  5. In the main function, a sample graph is created, edges are added, and Dijkstra's algorithm is applied to find and print the shortest paths from the source vertex (vertex 0).