Question: I need help in full JAVA code for : (I already have C++, Python. I need to learn Java only) function BREADTH-FIRST-SEARCH(problem) returns a solution,

I need help in full JAVA code for : (I already have C++, Python. I need to learn Java only)

function BREADTH-FIRST-SEARCH(problem) returns a solution, or failure

node ? a node with STATE = problem.INITIAL-STATE, PATH-COST = 0 if problem.GOAL-TEST(node.STATE) then return SOLUTION(node) frontier ? a FIFO queue with node as the only element explored ? an empty set

loop do if EMPTY?(frontier) then return failure node?POP(frontier) /*choosestheshallowestnodeinfrontier */ add node.STATE to explored for each action in problem.ACTIONS(node.STATE) do

child ?CHILD-NODE(problem,node,action) if child.STATE is not in explored or frontier then

if problem.GOAL-TEST(child.STATE) then return SOLUTION(child) frontier ?INSERT(child,frontier)

Figure 3.11 Breadth-first search on a graph.

8-puzzle is a problem where you have total 9 blocks as shown in the figure below. 8-blocks/cells are marked with a number from 1 to 8 and one cell is blank/empty, the goal is to organize numbered block in clockwise in an ascending order (shown in the final state). Given an initial state and final state below I need help in finding an BFS/DFS algorithm to solve the following 8-puzzle problem. The BFS/DFS algorithm should show all intermediate states and until it reaches to the final states. The JAVA code should be executable and print all the states while executing.

283 164 7 5 Initial state (vertex) 123 8 87 4 765

283 164 7 5 Initial state (vertex) 123 8 87 4 765 Final goal state/vertex

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!