h = The number of steps it would take to solve the problem if it was possible to swap any tile with the "space".

This heuristic also known as Gaschnig's heuristic. It is an admissible heuristic, since it underestimates the distance function of the problem and gives a closer approximation of the distance.

The heuristic function can be implemented by using 2 arrays: P – represents the current permutation. B – the location of element i in the permutation array.

The algorithm:Iteratively swap P[B[n]] with P[B[B[n]]] (for the n-puzzle)

For Example (The 8-Puzzle):

Current state: 29613478
goal state: 123456789 (9 represents the empty space)

Related Problems:N-PuzzleType:heuristic functionh = The number of steps it would take to solve the problem if it was possible to swap any tile with the "space".

This heuristic also known as Gaschnig's heuristic. It is an admissible heuristic, since it underestimates the distance function of the problem and gives a closer approximation of the distance.

The heuristic function can be implemented by using 2 arrays:

P– represents the current permutation.B– the location of element i in the permutation array.The algorithm:Iteratively swap P[B[n]] with P[B[B[n]]] (for the n-puzzle)For Example(The 8-Puzzle):Current state: 29613478

goal state: 123456789 (9 represents the empty space)

IterationPB