Question: I need jave code to implement this search problem for DAN by DFS I have this class // Java program for different tree traversals /*

I need jave code to implement this search problem for DAN by DFS
 I need jave code to implement this search problem for DAN
I have this class
// Java program for different tree traversals
/* Class containing left and right child of current
node and key value*/
class Node
{
String key;
Node left, right,medile;
public Node(String item)
{
key = item;
left = right = null;
}
}
class BinaryTree
{
// Root of Binary Tree
Node root;
BinaryTree()
{
root = null;
}
/* Given a binary tree, print its nodes according to the
"bottom-up" postorder traversal. */
void printPostorder(Node node)
{
if (node == null)
return;
// first recur on left subtree
printPostorder(node.left);
// then recur on right subtree
printPostorder(node.right);
// now deal with the node
System.out.print(node.key + " ");
}
/* Given a binary tree, print its nodes in inorder*/
void printInorder(Node node)
{
if (node == null)
return;
/* first recur on left child */
printInorder(node.left);
/* then print the data of node */
System.out.print(node.key + " ");
/* now recur on right child */
printInorder(node.right);
}
/* Given a binary tree, print its nodes in preorder*/
void printPreorder(Node node)
{
if (node == null)
return;
/* first print data of node */
System.out.print(node.key + " ");
/* then recur on left sutree */
printPreorder(node.left);
printPreorder(node.medile);
/* now recur on right subtree */
printPreorder(node.right);
}
// Wrappers over above recursive functions
void printPostorder() { printPostorder(root); }
void printInorder() { printInorder(root); }
void printPreorder() { printPreorder(root); }
// Driver method
public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
tree.root= new Node(" ");
tree.root.left= new Node("D");
tree.root.left.left=new Node("DD");
tree.root.left.left.left=new Node("DDD");
tree.root.left.left.medile=new Node("DDN");
tree.root.left.left.right=new Node("DDA");
tree.root.left.medile=new Node("DN");
tree.root.left.medile.left=new Node("DND");
tree.root.left.medile.medile=new Node("DNN");
tree.root.left.medile.right=new Node("DNA");
tree.root.left.right=new Node("DA");
tree.root.left.right.left=new Node("DAD");
tree.root.left.right.right=new Node("DAN");
tree.root.medile=new Node("N");
tree.root.medile.left=new Node("NA");
tree.root.medile.medile=new Node("NN");
tree.root.medile.right=new Node("NA");
tree.root.right=new Node("A");
tree.root.right.left=new Node("AD");
tree.root.right.medile=new Node("AN");
tree.root.right.right=new Node("AA");
System.out.println("Preorder traversal of binary tree is ");
tree.printPreorder();
System.out.println(" ");
System.out.println("---------------------------------------------- ");
System.out.println(" Inorder traversal of binary tree is ");
tree.printInorder();
System.out.println(" ");
System.out.println("---------------------------------------------- ");
System.out.println(" Postorder traversal of binary tree is ");
tree.printPostorder();
System.out.println(" ");
System.out.println("---------------------------------------------- ");
}
}

Edit Problem Statement The example we will use is the case of a genetics professor searching for a name for her newborn baby boy - of course, it must only contain the letters D, N and A. The states in this search are strings of letters (but only Ds, Ns and As), and the initial state is an empty string. The goal state is "DAN" string. Also, the actions available are: 0 add a 'D' to an existing string (ii) add an 'N' to an existing string (iii) add an'A' to an existing string Think of the search graphically: by making each state a node in a tree and each action a branch, we can think of the search progressing as movement from node to node along branches in the tree and we say that a node in a search space has been expanded if the state that node represents has been visited and searched from. add N add A add N OD) (N (DA NDNNNA AD(ANAA DND) (DNN) (ONA

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 Databases Questions!