Expands the least-cost node first, ensuring the optimal path is found based on cumulative cost.
Explain code with DocComment! Try out your own code!