edu.princeton.cs.algs4.growingtree.experiments
Class TreeExperiment

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.experiments.TreeExperiment

public class TreeExperiment
extends java.lang.Object

This is the class analogous to TreeVisualization for experiments. It stores a set of trees and provides a simple API to perform operations on all of them simultaneously, with callbacks for logging. Included is an example of how it can be used to log the number of rotations at each height of the tree.

Author:
Josh Israel

Constructor Summary
TreeExperiment()
           
 
Method Summary
<P extends NodeProperties>
void
addTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, IExperimentLogger<P> logger)
          Adds a tree to the set of trees to run the experiment on.
 void delete(double d)
          Deletes a node from the tree
 void insert(double d)
          Insert an element into each of the trees
static void main(java.lang.String[] args)
           
 void search(double d)
          Perform a search for an element
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeExperiment

public TreeExperiment()
Method Detail

addTree

public <P extends NodeProperties> void addTree(java.lang.String name,
                                               P p,
                                               IInsertOperator<P> inserter,
                                               ISearchOperator<P> searcher,
                                               IDeleteOperator<P> deleter,
                                               IExperimentLogger<P> logger)
Adds a tree to the set of trees to run the experiment on.

Parameters:
name - Name of the tree to be created
p - Instance of the proper NodeProperties subclass
inserter - The IInsertOperator to be used for this tree
searcher - The ISearchOperator to be used for this tree
deleter - The IDeleteOperator to be used for this tree
logger - The IExperimentLogger to be used for this tree. This will receive callbacks from the tree when operations occur.

insert

public void insert(double d)
Insert an element into each of the trees

Parameters:
d - Key of the node to be inserted

search

public void search(double d)
Perform a search for an element

Parameters:
d - Key of node to be sought

delete

public void delete(double d)
Deletes a node from the tree

Parameters:
d - Key of node to be deleted

main

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