{"id":113326,"date":"2023-07-02T10:20:09","date_gmt":"2023-07-02T10:20:09","guid":{"rendered":"https:\/\/educacion.cc\/?p=113326"},"modified":"2023-07-06T14:33:51","modified_gmt":"2023-07-06T14:33:51","slug":"dijkstras-algorithm-example-step-by-step","status":"publish","type":"post","link":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/","title":{"rendered":"Dijkstra\u2019s Algorithm Example Step by Step"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Dijkstras_Algorithm_Example_Step_by_Step\" >Dijkstra\u2019s Algorithm Example Step by Step<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#How_to_Find_the_Shortest_Path_in_a_Graph\" >How to Find the Shortest Path in a Graph<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Curiosities_Statistics_Facts_and_Interesting_Information\" >Curiosities, Statistics, Facts, and Interesting Information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#What_is_Dijkstras_Algorithm\" >What is Dijkstra\u2019s Algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#How_does_Dijkstras_Algorithm_Work\" >How does Dijkstra\u2019s Algorithm Work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Example_Implementation\" >Example Implementation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#FAQs\" >FAQs<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Q_What_is_the_time_complexity_of_Dijkstras_Algorithm\" >Q: What is the time complexity of Dijkstra\u2019s Algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Q_Does_Dijkstras_Algorithm_work_for_graphs_with_negative_edge_weights\" >Q: Does Dijkstra\u2019s Algorithm work for graphs with negative edge weights?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#Q_Can_Dijkstras_Algorithm_handle_graphs_with_cycles\" >Q: Can Dijkstra\u2019s Algorithm handle graphs with cycles?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Dijkstras_Algorithm_Example_Step_by_Step\"><\/span>Dijkstra\u2019s Algorithm Example Step by Step<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Find_the_Shortest_Path_in_a_Graph\"><\/span>How to Find the Shortest Path in a Graph<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights, producing a shortest path tree. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.<\/p>\n<p>I\u2019ll share with you my personal experiences and tips that will help you understand and implement this algorithm. So, let\u2019s get started!<\/p>\n<\/section>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"Curiosities_Statistics_Facts_and_Interesting_Information\"><\/span>Curiosities, Statistics, Facts, and Interesting Information<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Dijkstra\u2019s Algorithm is widely used in many applications, such as road networks, computer networks, and social networks.<\/li>\n<li>The algorithm is named after the Dutch computer scientist Edsger W. Dijkstra, who developed it in 1956.<\/li>\n<li>Dijkstra\u2019s Algorithm is an example of a greedy algorithm, meaning it makes the locally optimal choice at each stage with the hope of finding a global optimum.<\/li>\n<li>The algorithm has a time complexity of O(V^2), where V is the number of nodes in the graph, but this can be improved to O(E+VlogV) with the use of a priority queue.<\/li>\n<li>The algorithm works correctly only for graphs with non-negative edge weights.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"What_is_Dijkstras_Algorithm\"><\/span>What is Dijkstra\u2019s Algorithm?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights, producing a shortest path tree. The algorithm works by maintaining a set of unvisited nodes and a set of tentative distances to those nodes. It starts at the source node and repeatedly selects the unvisited node with the smallest tentative distance, updates the distances of its neighbors, and marks it as visited. The algorithm terminates when all nodes have been visited or the smallest tentative distance among the unvisited nodes is infinity.<\/p>\n<\/section>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"How_does_Dijkstras_Algorithm_Work\"><\/span>How does Dijkstra\u2019s Algorithm Work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let\u2019s say we have the following weighted graph:<\/p>\n<p>\t\t\t<img src=https:\/\/i.imgur.com\/5l5Y5bK.png alt=Weighted Graph><\/p>\n<p>Our source node is A and our goal is to find the shortest path to all other nodes. We start by initializing our set of unvisited nodes and tentative distances:<\/p>\n<table>\n<thead>\n<tr>\n<th>Node<\/th>\n<th>Tentative Distance<\/th>\n<th>Visited?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A<\/td>\n<td>0<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>C<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>F<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Next, we select the node with the smallest tentative distance, which is A, and mark it as visited. We update the distances of its neighbors:<\/p>\n<table>\n<thead>\n<tr>\n<th>Node<\/th>\n<th>Tentative Distance<\/th>\n<th>Visited?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A<\/td>\n<td>0<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>5<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>C<\/td>\n<td>3<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>9<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>F<\/td>\n<td>\u221e<\/td>\n<td>No<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We repeat this process until all nodes have been visited:<\/p>\n<table>\n<thead>\n<tr>\n<th>Node<\/th>\n<th>Tentative Distance<\/th>\n<th>Visited?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A<\/td>\n<td>0<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>5<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>C<\/td>\n<td>3<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>8<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>10<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>F<\/td>\n<td>13<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We can see that the shortest path from A to F is A -> C -> D -> F with a distance of 13.<\/p>\n<\/section>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"Example_Implementation\"><\/span>Example Implementation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let\u2019s implement Dijkstra\u2019s Algorithm in Python:<\/p>\n<pre><code>import heapq\n\ndef dijkstra(graph, start):\n    distances = {node: float('inf') for node in graph}\n    distances[start] = 0\n    queue = [(0, start)]\n    while queue:\n        current_distance, current_node = heapq.heappop(queue)\n        if current_distance > distances[current_node]:\n            continue\n        for neighbor, weight in graph[current_node].items():\n            distance = current_distance + weight\n            if distance &lt; distances[neighbor]:\n                distances[neighbor] = distance\n                heapq.heappush(queue, (distance, neighbor))\n    return distances\n\ngraph = {\n    'A': {'B': 5, 'C': 3},\n    'B': {'A': 5, 'C': 1, 'D': 3},\n    'C': {'A': 3, 'B': 1, 'D': 2},\n    'D': {'B': 3, 'C': 2, 'E': 4, 'F': 3},\n    'E': {'D': 4, 'F': 7},\n    'F': {'D': 3, 'E': 7}\n}\n\nprint(dijkstra(graph, 'A'))<\/code><\/pre>\n<p>The output will be:<\/p>\n<pre><code>{'A': 0, 'B': 5, 'C': 3, 'D': 8, 'E': 10, 'F': 13}<\/code><\/pre>\n<p>We can see that the implementation produces the correct result.<\/p>\n<\/section>\n<section>\n<h2><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Q_What_is_the_time_complexity_of_Dijkstras_Algorithm\"><\/span>Q: What is the time complexity of Dijkstra\u2019s Algorithm?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A: The time complexity of Dijkstra\u2019s Algorithm is O(V^2), where V is the number of nodes in the graph. However, with the use of a priority queue, the time complexity can be improved to O(E+VlogV), where E is the number of edges in the graph.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Q_Does_Dijkstras_Algorithm_work_for_graphs_with_negative_edge_weights\"><\/span>Q: Does Dijkstra\u2019s Algorithm work for graphs with negative edge weights?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A: No, Dijkstra\u2019s Algorithm works correctly only for graphs with non-negative edge weights. For graphs with negative edge weights, we need to use other algorithms, such as Bellman-Ford Algorithm or Floyd-Warshall Algorithm.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Q_Can_Dijkstras_Algorithm_handle_graphs_with_cycles\"><\/span>Q: Can Dijkstra\u2019s Algorithm handle graphs with cycles?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A: Yes, Dijkstra\u2019s Algorithm can handle graphs with cycles, as long as there are no negative cycles. A negative cycle is a cycle whose total weight is negative, and it can cause the algorithm to enter an infinite loop.<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights, &#8230; <a title=\"Dijkstra\u2019s Algorithm Example Step by Step\" class=\"read-more\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/\" aria-label=\"More on Dijkstra\u2019s Algorithm Example Step by Step\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-113326","post","type-post","status-publish","format-standard","hentry","category-step-by-step"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"John Johnson\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\n\t\t<!-- Google tag (gtag.js) -->\n<script async src=\"https:\/\/www.googletagmanager.com\/gtag\/js?id=G-16SK0R9CQB\"><\/script>\n<script>\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag('js', new Date());\n\n  gtag('config', 'G-16SK0R9CQB');\n<\/script>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3987500858204711\"\n     crossorigin=\"anonymous\"><\/script>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Step-by-Step Tutorials - My WordPress Blog\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Dijkstra\u2019s Algorithm Example Step by Step\" \/>\n\t\t<meta property=\"og:description\" content=\"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-07-02T10:20:09+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-07-06T14:33:51+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Dijkstra\u2019s Algorithm Example Step by Step\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#blogposting\",\"name\":\"Dijkstra\\u2019s Algorithm Example Step by Step\",\"headline\":\"Dijkstra\\u2019s Algorithm Example Step by Step\",\"author\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/author\\\/admin332\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/#organization\"},\"datePublished\":\"2023-07-02T10:20:09+00:00\",\"dateModified\":\"2023-07-06T14:33:51+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#webpage\"},\"articleSection\":\"Step-by-Step\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/category\\\/step-by-step\\\/#listItem\",\"name\":\"Step-by-Step\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/category\\\/step-by-step\\\/#listItem\",\"position\":2,\"name\":\"Step-by-Step\",\"item\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/category\\\/step-by-step\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#listItem\",\"name\":\"Dijkstra\\u2019s Algorithm Example Step by Step\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#listItem\",\"position\":3,\"name\":\"Dijkstra\\u2019s Algorithm Example Step by Step\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/category\\\/step-by-step\\\/#listItem\",\"name\":\"Step-by-Step\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/#organization\",\"name\":\"Step by Step Guides\",\"description\":\"My WordPress Blog\",\"url\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/author\\\/admin332\\\/#author\",\"url\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/author\\\/admin332\\\/\",\"name\":\"John Johnson\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#webpage\",\"url\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/\",\"name\":\"Dijkstra\\u2019s Algorithm Example Step by Step\",\"description\":\"Dijkstra\\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\\u2019m John Johnson and in this article, I\\u2019ll guide you step by step through Dijkstra\\u2019s Algorithm Example. Dijkstra\\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/dijkstras-algorithm-example-step-by-step-tutorial\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/author\\\/admin332\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/author\\\/admin332\\\/#author\"},\"datePublished\":\"2023-07-02T10:20:09+00:00\",\"dateModified\":\"2023-07-06T14:33:51+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/#website\",\"url\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/\",\"name\":\"Step by Step Guides\",\"description\":\"My WordPress Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/educacion.cc\\\/en\\\/step-by-step\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Dijkstra\u2019s Algorithm Example Step by Step","description":"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,","canonical_url":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":"&lt;!-- Google tag (gtag.js) --&gt;\n&lt;script async src=\"https:\/\/www.googletagmanager.com\/gtag\/js?id=G-16SK0R9CQB\"&gt;&lt;\/script&gt;\n&lt;script&gt;\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag('js', new Date());\n\n  gtag('config', 'G-16SK0R9CQB');\n&lt;\/script&gt;\n&lt;script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3987500858204711\"\n     crossorigin=\"anonymous\"&gt;&lt;\/script&gt;"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#blogposting","name":"Dijkstra\u2019s Algorithm Example Step by Step","headline":"Dijkstra\u2019s Algorithm Example Step by Step","author":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/author\/admin332\/#author"},"publisher":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/#organization"},"datePublished":"2023-07-02T10:20:09+00:00","dateModified":"2023-07-06T14:33:51+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#webpage"},"isPartOf":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#webpage"},"articleSection":"Step-by-Step"},{"@type":"BreadcrumbList","@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step#listItem","position":1,"name":"Home","item":"https:\/\/educacion.cc\/en\/step-by-step","nextItem":{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/#listItem","name":"Step-by-Step"}},{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/#listItem","position":2,"name":"Step-by-Step","item":"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/","nextItem":{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#listItem","name":"Dijkstra\u2019s Algorithm Example Step by Step"},"previousItem":{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#listItem","position":3,"name":"Dijkstra\u2019s Algorithm Example Step by Step","previousItem":{"@type":"ListItem","@id":"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/#listItem","name":"Step-by-Step"}}]},{"@type":"Organization","@id":"https:\/\/educacion.cc\/en\/step-by-step\/#organization","name":"Step by Step Guides","description":"My WordPress Blog","url":"https:\/\/educacion.cc\/en\/step-by-step\/"},{"@type":"Person","@id":"https:\/\/educacion.cc\/en\/step-by-step\/author\/admin332\/#author","url":"https:\/\/educacion.cc\/en\/step-by-step\/author\/admin332\/","name":"John Johnson"},{"@type":"WebPage","@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#webpage","url":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/","name":"Dijkstra\u2019s Algorithm Example Step by Step","description":"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/#website"},"breadcrumb":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/#breadcrumblist"},"author":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/author\/admin332\/#author"},"creator":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/author\/admin332\/#author"},"datePublished":"2023-07-02T10:20:09+00:00","dateModified":"2023-07-06T14:33:51+00:00"},{"@type":"WebSite","@id":"https:\/\/educacion.cc\/en\/step-by-step\/#website","url":"https:\/\/educacion.cc\/en\/step-by-step\/","name":"Step by Step Guides","description":"My WordPress Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/educacion.cc\/en\/step-by-step\/#organization"}}]},"og:locale":"en_US","og:site_name":"Step-by-Step Tutorials - My WordPress Blog","og:type":"article","og:title":"Dijkstra\u2019s Algorithm Example Step by Step","og:description":"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,","og:url":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/","article:published_time":"2023-07-02T10:20:09+00:00","article:modified_time":"2023-07-06T14:33:51+00:00","twitter:card":"summary_large_image","twitter:title":"Dijkstra\u2019s Algorithm Example Step by Step","twitter:description":"Dijkstra\u2019s Algorithm Example Step by Step How to Find the Shortest Path in a Graph Introduction Hi, I\u2019m John Johnson and in this article, I\u2019ll guide you step by step through Dijkstra\u2019s Algorithm Example. Dijkstra\u2019s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights,"},"aioseo_meta_data":{"post_id":"113326","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2023-04-23 06:34:12","updated":"2023-07-08 10:26:09","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/educacion.cc\/en\/step-by-step\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/\" title=\"Step-by-Step\">Step-by-Step<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDijkstra\u2019s Algorithm Example Step by Step\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/educacion.cc\/en\/step-by-step"},{"label":"Step-by-Step","link":"https:\/\/educacion.cc\/en\/step-by-step\/category\/step-by-step\/"},{"label":"Dijkstra\u2019s Algorithm Example Step by Step","link":"https:\/\/educacion.cc\/en\/step-by-step\/dijkstras-algorithm-example-step-by-step-tutorial\/"}],"_links":{"self":[{"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/posts\/113326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/comments?post=113326"}],"version-history":[{"count":1,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/posts\/113326\/revisions"}],"predecessor-version":[{"id":115781,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/posts\/113326\/revisions\/115781"}],"wp:attachment":[{"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/media?parent=113326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/categories?post=113326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/educacion.cc\/en\/step-by-step\/wp-json\/wp\/v2\/tags?post=113326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}