I don't see the definition of wasVisited. However, it seems like you should use a map[string]bool instead of []string for your visited set so that you don't have to walk over the list.
If you're walking over the list of visited nodes for every edge, your implementation runs in time proportional to $O(|V|*|E|)$! (which defeats the point of using a heap)
You can also simplify yourgetPath implementation. There's no reason to treat the source node specially. You can instead initialize the visited set to empty and the heap with just the source, to be visited first. (Notice how the beginning of the function duplicates the contents of the loop!)
for this reason I love to share because is good for me, to improve and learn, at the moment that I wrote the code I was focus in other things and ignore other, thanks master you are 1000% right. <3
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't see the definition of
wasVisited
. However, it seems like you should use amap[string]bool
instead of[]string
for yourvisited
set so that you don't have to walk over the list.If you're walking over the list of visited nodes for every edge, your implementation runs in time proportional to $O(|V|*|E|)$! (which defeats the point of using a heap)
You can also simplify your
getPath
implementation. There's no reason to treat the source node specially. You can instead initialize thevisited
set to empty and the heap with just the source, to be visited first. (Notice how the beginning of the function duplicates the contents of the loop!)for this reason I love to share because is good for me, to improve and learn, at the moment that I wrote the code I was focus in other things and ignore other, thanks master you are 1000% right. <3