Class Searches

java.lang.Object
  |
  +--Searches

public class Searches
extends java.lang.Object

Trying out various tree searches.

Version:
3/31/2003
Author:
Dave Matuszek

Constructor Summary
Searches()
           
 
Method Summary
(package private) static boolean bfs(Tree root)
          Performs a breadth-first search, starting from the given node, for any node that satisfies the condition isGoal(node).
(package private) static Tree createTree()
          Creates and returns a tree for use in testing the other methods.
(package private) static boolean dfs(Tree root)
          Performs a depth-first search, starting from the given node, for any node that satisfies the condition isGoal(node).
(package private) static void dump(java.util.Stack stack)
          Prints the contents of the stack (top to the left).
(package private) static boolean isGoal(Tree node)
          Defines a couple of nodes in the tree to be goal nodes.
static void main(java.lang.String[] args)
           
(package private) static void postorderPrint(Tree node)
          Traverses the given tree in postorder, printing node values on a single line.
(package private) static void postorderPrint(Tree node, java.lang.String indent)
          Traverses the given tree in postorder, printing node values indented and on multiple lines.
(package private) static void preorderPrint(Tree node)
          Traverses the given tree in preorder, printing node values on a single line.
(package private) static void preorderPrint(Tree node, java.lang.String indent)
          Traverses the given tree in preorder, printing node values indented and on multiple lines.
(package private) static boolean recursiveDfs(Tree node)
          Performs a depth-first search, starting from the given node, for any node that satisfies the condition isGoal(node), and prints the path from the goal back to the root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Searches

public Searches()
Method Detail

bfs

static boolean bfs(Tree root)
Performs a breadth-first search, starting from the given node, for any node that satisfies the condition isGoal(node).

Parameters:
root - The root of the tree or subtree to be searched.
Returns:
True if a goal node could be found.

createTree

static Tree createTree()
Creates and returns a tree for use in testing the other methods.


dfs

static boolean dfs(Tree root)
Performs a depth-first search, starting from the given node, for any node that satisfies the condition isGoal(node).

Parameters:
root - The root of the tree or subtree to be searched.
Returns:
True if a goal node could be found.

dump

static void dump(java.util.Stack stack)
Prints the contents of the stack (top to the left).


isGoal

static boolean isGoal(Tree node)
Defines a couple of nodes in the tree to be goal nodes. There is no "deeper meaning" to these nodes; it's just a hack to test out the search methods.


main

public static void main(java.lang.String[] args)

postorderPrint

static void postorderPrint(Tree node)
Traverses the given tree in postorder, printing node values on a single line.


postorderPrint

static void postorderPrint(Tree node,
                           java.lang.String indent)
Traverses the given tree in postorder, printing node values indented and on multiple lines. I did this out of curiosity, and find the resultant output very difficult to read.


preorderPrint

static void preorderPrint(Tree node)
Traverses the given tree in preorder, printing node values on a single line.


preorderPrint

static void preorderPrint(Tree node,
                          java.lang.String indent)
Traverses the given tree in preorder, printing node values indented and on multiple lines.


recursiveDfs

static boolean recursiveDfs(Tree node)
Performs a depth-first search, starting from the given node, for any node that satisfies the condition isGoal(node), and prints the path from the goal back to the root.

Returns:
True if a goal node could be found.


Generated by BlueJ