133
Implementation
The full graph hash table looks like this.
Next you need a hash table to store the costs for each node.
The
cost
of a node is how long
it takes to get to that
node from the start. You know it takes 2 minutes from
Start to node B. You know it takes 6
minutes to get to
node A (although you may find a path that takes less
time). You don’t know how
long it takes to get to the
finish. If you don’t know the cost yet,
you put down
infinity. Can you represent
infinity
in Python?
Turns
out, you can:
infinity = float(“inf”)
Here’s the code to make the costs table:
infinity = float(“inf”)
costs = {}
costs[“a”] = 6
costs[“b”] = 2
costs[“fin”] = infinity
You also need another hash table for the parents: