Question: So i know i have to wirte a search method but i need some hint please Graph: import java.util.ArrayList; /* * A class representing a
So i know i have to wirte a search method but i need some hint please

Graph:
import java.util.ArrayList;
/* * A class representing a Graph as an adjacency matrix, * and providing search functions for the Graph. */
/* * Student 1 Name: * Student 1 Number: * * Student 2 Name: * Student 2 Number: * */
public class Graph {
boolean[][] adjMat;
// In the adjacency matrix representation of a Graph, // if adjMat[i][j] == true, then you can move from // node i to node j. // i.e. j is a neighbour of i. // The constructor builds the adjacency matrix, // with initially all values false. public Graph(int size) { adjMat = new boolean[size][size]; for (int i=0; i
// Add a transition to the adjacency matrix, // i.e. a neighbour relation between two nodes. public void add(int from, int to) { adjMat[from][to] = true; }
// Carry out uninformed search of the Graph, // from the start node to goal node. public boolean search(int start, int goal, boolean dp) { // The frontier is an ArrayList of Paths. ArrayList
public static void main(String[] args) { // Create a Graph containing 7 nodes Graph g = new Graph(7); // Add edges to the Graph g.add(0, 1); g.add(0, 2); g.add(1,5); g.add(1,6); g.add(2, 3); g.add(3, 4); // select a search type boolean depthFirst = false; // start searching g.search(0,4, depthFirst); } }
path:
import java.util.ArrayList;
/* * DO NOT EDIT THIS CLASS * * A very simple class representing a Path (sequence of nodes). * * This is really just a wrapper for an ArrayList, with a few * helpful methods. */
public class Path {
// The only instance field is an ArrayList of Integers. // i.e. a Path consists of a sequence of nodes, and the // nodes are identified by their Integer id's. private ArrayList
2. To-Do You must complete the implementation of the search() method in the Graph class. That is the only part of the code you should change. The search() method must do the following: Display (using a print statement) every node that it inspects. If it finds the goal, display the path to a goal. Return true if the goal is found. Return false otherwise. Use either depth-first or breadth-first search, depending on the third parameter of the method. Note: in the lectures we talked about depth-first treating the frontier like a stack, and breadth-first treating it like a queue. In this code, we use an ArrayList regardless of the search method. You can just select Paths from one end of the ArrayList or the other, depending on the search method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
