{"id":26031649,"url":"https://github.com/nelsonbn/algorithms-data-structures-dijkstra","last_synced_at":"2026-02-21T04:33:13.791Z","repository":{"id":197881614,"uuid":"695588591","full_name":"NelsonBN/algorithms-data-structures-dijkstra","owner":"NelsonBN","description":"Algorithms and Data Structures - Dijkstra","archived":false,"fork":false,"pushed_at":"2025-03-02T13:28:39.000Z","size":610,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T16:13:49.769Z","etag":null,"topics":["algorithms","algorithms-and-data-structures","data-structures","dijkstra","graphs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NelsonBN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-23T16:17:14.000Z","updated_at":"2025-03-22T15:36:05.000Z","dependencies_parsed_at":"2025-03-02T14:38:58.175Z","dependency_job_id":null,"html_url":"https://github.com/NelsonBN/algorithms-data-structures-dijkstra","commit_stats":null,"previous_names":["nelsonbn/algorithms-dijkistra","nelsonbn/algorithms-data-structures-dijkistra","nelsonbn/algorithms-data-structures-dijkstra"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonBN%2Falgorithms-data-structures-dijkstra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonBN%2Falgorithms-data-structures-dijkstra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonBN%2Falgorithms-data-structures-dijkstra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NelsonBN%2Falgorithms-data-structures-dijkstra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NelsonBN","download_url":"https://codeload.github.com/NelsonBN/algorithms-data-structures-dijkstra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065282,"owners_count":21041872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","algorithms-and-data-structures","data-structures","dijkstra","graphs"],"created_at":"2025-03-06T20:18:52.605Z","updated_at":"2026-02-21T04:33:13.756Z","avatar_url":"https://github.com/NelsonBN.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Algorithms and Data Structures - Dijkstra\n\n- [Description](#description)\n- [Pseudocode](#pseudocode)\n- [Demos](#demos)\n  - [Graphs used in the demos](#graphs-used-in-the-demos)\n  - [Implementation](#implementation)\n    - [`diagram.py`](#diagrampy)\n- [References](#references)\n- [Contributions](#contributions)\n\n\n\n## Description\n\nThe Dijkstra Algorithm falls under the category of \"Shortest Path\" problems in graphs. This is a classic optimization problem in graph theory, where the goal is to find the lowest weight path between two vertices in a weighted graph. The Dijkstra algorithm is particularly efficient for graphs with non-negative weights on the edges. Solving shortest path problems is crucial in various areas, such as computer networks, route planning, and logistics.\n\n\n\n## Pseudocode\n\n**Initialization:**\n\n1. Select a source vertex;\n2. Create a HashTable to store the vertices that have already been visited;\n3. Create a dictionary to store the distances from the source to each vertex, initializing the distance from the source to itself as 0;\n4. Create a Min-heap queue and add the source vertex with distance 0;\n\n**Processing:**\n\n5. While the queue is not empty and the number of visited vertices is less than the number of vertices in the graph:\n   1. Retrieve the vertex with the smallest accumulated distance from the queue;\n   2. If we are looking for the shortest path to a specific vertex, at this step, we can check if the current vertex is the destination vertex and terminate the neighbor processing loop;\n   3. If the current vertex has already been visited, skip to the next vertex and go back to step 5.1;\n   4. Add the current vertex to the HashTable of visited vertices;\n   5. For each neighbor of the current vertex in the graph:\n      1. Calculate the accumulated distance to the current vertex + the distance from the current vertex to the neighbor;\n      2. If the neighbor is not in the distance dictionary or the accumulated distance is less than the neighbor's distance in the dictionary:\n         1. Update the neighbor's distance in the dictionary;\n         2. Add the neighbor to the queue with the accumulated distance to enter the priority queue;\n\n**Finalization:**\n\n6. If we are looking for the shortest path to a specific vertex, we can terminate when the destination vertex is found;\n   1. Then, we traverse the dictionary from the destination to the source to obtain the shortest path;\n7. If we are looking for the shortest path to all vertices, we can terminate when the queue is empty or all vertices have been visited;\n   1. Then, we can return the distance dictionary.\n\n\n\n## Demos\n\n### Graphs used in the demos\n\n* [Directed Graph (Digraph)](graph1.md)\n* [Undirected Graph](graph2.md)\n* [Disconnected Graph](graph3.md)\n\n### Implementation\n\n#### `diagram.py`\nTo run this demo, you need to install the following packages:\n\n```bash\npip install networkx\npip install matplotlib\n```\n\n\n\n## References\n\n* [Other Algorithms \u0026 Data Structures](https://github.com/NelsonBN/algorithms-data-structures)\n* [usfca.edu](https://www.cs.usfca.edu/~galles/visualization/Dijkstra.html)\n* [Pseudocode diagram](https://whimsical.com/djikstra-ULBhe3Sp9aVMKBzBiNNQLN)\n\n\n\n## Contributions\n\n* [@giovannymassuia](https://github.com/giovannymassuia)\n* [@wilsonneto-dev](https://github.com/wilsonneto-dev)\n* [@Matheus](https://www.linkedin.com/in/matheus-silva-santos-90383234/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnelsonbn%2Falgorithms-data-structures-dijkstra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnelsonbn%2Falgorithms-data-structures-dijkstra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnelsonbn%2Falgorithms-data-structures-dijkstra/lists"}