Pseudocode
procedure UniformCostSearch(Graph, root, goal)
node := root, cost = 0frontier := priority queue containing node onlyexplored := empty setdoif frontier is emptyreturn failure
node := frontier.popif node is goalreturn solution
explored.add(node)for each of node's neighbors nif n is not in exploredif n is not in frontierfrontier.add(n)
else if n is in frontier with higher costreplace existing node with n
Read more about this topic: Uniform-cost Search