Skip to content

Instantly share code, notes, and snippets.

@devdil
Created October 22, 2013 16:07
Show Gist options
  • Save devdil/7103429 to your computer and use it in GitHub Desktop.
Save devdil/7103429 to your computer and use it in GitHub Desktop.
All about different Algorithm Strategies..-Divide and Conquer,Greedy,Backtracking,Graph Traversals,
package test;
public class DepthFirstSearch {
public static void main(String args[])
{
system.out.println(BinaryTree.solvable(BinaryTree.makeTree()));
}
}
class BinaryTree
{
BinaryTree leftchild=null;
BinaryTree rightchild=null;
boolean isGoalNode=false;
String nodeName;
BinaryTree(String name,BinaryTree leftchild,BinaryTree rightchild,boolean isGoalNode)
{
this.nodeName=name;
this.leftchild=leftchild;
this.rightchild=rightchild;
this.isGoalNode=isGoalNode;
}
static BinaryTree makeTree() {
BinaryTree root,a,b,c,d,e,f;
c=new BinaryTree("c",null,null,false);
d=new BinaryTree("d",null,null,false);
e=new BinaryTree("e",null,null,true);
f=new BinaryTree("f",null,null,false);
a=new BinaryTree("a",c,d,false);
b=new BinaryTree("c",e,f,false);
root=new BinaryTree("c",a,b,false);
return root;
}
static boolean solvable(BinaryTree node)
{
if(node.isGoalNode)
return true;
if(node.leftchild!=null && solvable(node.leftchild))
return true;
if(node.rightchild!=null && solvable(node.rightchild))
return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment