Looking for a java library that has implemented Binary Tree

Esey picture Esey · Mar 28, 2012 · Viewed 44.6k times · Source

Is there a java library that has Binary Tree that I can use? I am not looking forward to test and implement my own.

Answer

Joni picture Joni · Mar 28, 2012

The Java standard API only contains libraries that are universally useful and non-trivial to implement. A basic tree is trivial to implement:

class BinaryTree {
    BinaryTree left;
    BinaryTree right;
    Object value;
}

Non-trivial trees are not universally useful: either they are needed as a part of the application data model, which is better modeled using domain specific classes (component has-a list of sub-components), or they are used as a part of a specific algorithm. Algorithms usually require a specific structure from the nodes (e.g. the color or weight of the node needed to maintain the tree balanced), so a generic tree node makes little sense.