I have an application which has a tree structure where each parent has 3 or more child nodes. Each node contains an integer value. I am trying to see if a given integer value is present in the tree. How do I do a Depth First Search on the tree? I understand that we start at the root and then explore as far as possible in each branch of the tree. I am having trouble implementing this in Java though. Would I need some sort of other data structure to do the traversal?
It would be helpful if someone could give a sample implementation.
The tree structure is as follows. I need to implement the findNode function:
public class Tree{
public Node{
Node [] children;
int val;
public Node[] getChildren(){
return children;
}
public getVal(int i){
return children[i].val;
}
}
public boolean findNode(int val){
}
}