java中的二叉索引树
我正在学习如何实现二叉索引树。我应该如何用一组字符串作为输入来构建二叉树?我相信有两种数据结构1)常规二叉树-我们按顺序进行二叉索引树java中的二叉索引树,java,dictionary,binary-tree,binary-search-tree,b-tree,Java,Dictionary,Binary Tree,Binary Search Tree,B Tree,我正在学习如何实现二叉索引树。我应该如何用一组字符串作为输入来构建二叉树?我相信有两种数据结构1)常规二叉树-我们按顺序进行二叉索引树 public static void main(String[] args) { String[] docs = {"The idea is that all are strings", "position of the node is considered", "Bei
public static void main(String[] args)
{
String[] docs = {"The idea is that all are strings",
"position of the node is considered",
"Being positive helps",
"I want to learn then add and search in the tree"
};
}
Bstnode
public class BSTNode
{
private String key;
private Object value;
private BSTNode left, right;
public BSTNode( String key, Object value )
{
this.key = key;
this.value = value;
}
//if key not found in BST then it is added. If jey already exists then that node's value
//is updated.
public void put( String key, Object value )
{
if ( key.compareTo( this.key ) < 0 )
{
if ( left != null )
{
left.put( key, value );
}
else
{
left = new BSTNode( key, value );
}
}
else if ( key.compareTo( this.key ) > 0 )
{
if ( right != null )
{
right.put( key, value );
}
else
{
right = new BSTNode( key, value );
}
}
else
{
//update this one
this.value = value;
}
}
//find Node with given key and return it's value
public Object get( String key )
{
if ( this.key.equals( key ) )
{
return value;
}
if ( key.compareTo( this.key ) < 0 )
{
return left == null ? null : left.get( key );
}
else
{
return right == null ? null : right.get( key );
}
}
公共类节点
{
私钥;
私人客体价值;
私有节点左、右;
公共节点(字符串键、对象值)
{
this.key=key;
这个值=值;
}
//如果在BST中找不到密钥,则添加该密钥。如果jey已存在,则添加该节点的值
//已更新。
公共void put(字符串键、对象值)
{
if(key.compareTo(this.key)<0)
{
if(左!=null)
{
左。输入(键、值);
}
其他的
{
左=新节点(键、值);
}
}
如果(key.compareTo(this.key)>0,则为else
{
if(右!=null)
{
对。输入(键、值);
}
其他的
{
右=新节点(键、值);
}
}
其他的
{
//更新这个
这个值=值;
}
}
//找到具有给定键的节点并返回其值
公共对象获取(字符串键)
{
如果(此键等于(键))
{
返回值;
}
if(key.compareTo(this.key)<0)
{
return left==null?null:left.get(key);
}
其他的
{
return right==null?null:right.get(key);
}
}
}
请告诉我一个关于构建二元索引树的好教程或开始。
树
和列表
在Java中应该是通用的。把自己限制在字符串中是没有意义的
任何关于数据结构的好书都会给你一个良好的开端
我用Java做过这个。欢迎您访问来源:
试试本教程注释:或BIT(也称为Fenwick树)与二进制搜索树(又称BST)关系不大或根本没有关系;它们用于高效查询给定点/节点上的运行总数或给定范围内的总和等目的。因此,这些野兽与二进制搜索树完全不同。注意,二叉搜索树不是二叉索引树,即使它被用作某种索引。