Click here to Skip to main content
14,640,670 members
Rate this:
Please Sign up or sign in to vote.
i want to implement this Dijkstra's pseudocode exactly to my python graph.

Dijkstra's Algorithm DIJKSTRA(G,s,d)  //graph, source, destination   
v ← s //v is always our currently scanned node
    for all n in G.vertices ← ∞ ← 0  //Source is no distance from itself
    visited ← []
    while v≠d
         for all vertices, u, adjacent to v
            if[u].w <
                u.pre ← v         //Store the return path
        min ← ∞        
     for all nodes n ∈ V 
           if n ∉ visited ∧ < min
                v ← n
                min ←

What I have tried:

graph = {

'a':{'b':3,'c':4, 'd':7},
'd':{'e':3, 'g':6},
'e':{'g':3, 'h':4},
'f':{'e':1, 'h':8},

def dijkstra(graph,start,goal):
Updated 30-May-20 22:13pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100