Hello, please help implement the depth search method below, cases are in comment
ID: 3571806 • Letter: H
Question
Hello, please help implement the depth search method below, cases are in comments of code.
public class Graph {
private Vector<GraphNode> nodes;
public Graph() {
nodes = new Vector<GraphNode>();
}
public void addNode (GraphNode new_node) {
nodes.add(new_node);
}
public boolean isValidName(String i) {
for (GraphNode it : nodes) {
if (it.getName().equals(i)) {
return true;
}
}
//System.out.println("Node " + i + " invalid");
return false;
}
public GraphNode getNode(String a) throws IllegalArgumentException {
for (GraphNode it : nodes) {
if (it.getName().equals(a)) {
return it;
}
}
throw new IllegalArgumentException(a + ": no such node is not present");
}
public void print() {
for (GraphNode it : nodes) {
it.print();
}
}
public String depthFirstSearch(GraphNode start, GraphNode end) {
// use a vector to track the locations that have been visited
Vector<GraphNode> visited = new Vector<GraphNode>();
// TODO: What should you use if you want to ensure that
// DFS uses the LIFO principle?
// TODO: initialize the start at the given start location
// loop until there are no new elements to explore on the stack
while (!to_check.isEmpty()) {
// TODO: get the first element to check
// TODO: check if the last node in the current path is the destination
// if it is, return the current path's string as this is a valid
// path to the destination
// TODO: otherwise we add the last node to the visited
// and check the edges of the last node, which for
// each we check the destination node of the edge
// and if we haven't been there already add a new path
// that includes the destination node to be checked
// ** use path.extend(GraphNode)
}
return null;
}
Explanation / Answer
The CHT isn't always a fastidiously specified set of rules, as an alternative there are some of one-of-a-kind procedures that may be taken in its implementation. but, by and large, there are 3 crucial steps which are not unusual to all.
Accumulator Array Computation.
Foreground pixels of excessive gradient are certain as being candidate pixels and are allowed to forged ‘votes' inside the accumulator array.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.