Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a java library that has implemented Binary Tree [closed]

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

like image 918
Esey Avatar asked Mar 28 '12 02:03

Esey


People also ask

Is there a library of binary tree in Java?

The TreeSet and TreeMap classes are the most obvious implementation of binary tree data structure in the Java API Library. For the high-level users, the rules of data organization do not make any difference in its usages.

Is there a binary search tree class in Java?

You will learn to Create a BST, Insert, Remove and Search an Element, Traverse & Implement a BST in Java: A Binary search tree (referred to as BST hereafter) is a type of binary tree. It can also be defined as a node-based binary tree. BST is also referred to as 'Ordered Binary Tree'.

What is a binary search tree in Java?

A binary tree is a recursive data structure where each node can have 2 children at most. A common type of binary tree is a binary search tree, in which every node has a value that is greater than or equal to the node values in the left sub-tree, and less than or equal to the node values in the right sub-tree.

How are binary search trees implemented?

Insertion in Binary Search treeTo insert an element in BST, we have to start searching from the root node; if the node to be inserted is less than the root node, then search for an empty location in the left subtree. Else, search for the empty location in the right subtree and insert the data.


2 Answers

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.

like image 157
Joni Avatar answered Oct 16 '22 05:10

Joni


What about http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html

A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

like image 33
Greg Kopff Avatar answered Oct 16 '22 04:10

Greg Kopff