Making Heuristic State Space Search Optimal

Q: What is different about the two vertices representing J in the search tree?

A: One is deeper in the tree than the other.

Recall that h(s) is the heuristic value for any state s in the search tree.

Let d(s) be the depth of s in the search tree.

Then if we order the priority queue by the key value h(s) + d(s), state J-as-a-descendant-of-C will be removed from the priority queue before state J-as-a-descendant-of-B, and the shorter path will be found first.