B+ tree

B+ tree

View Answers

November 23, 2008 at 10:22 PM

Hi friend,

Code to help in solving the problem :

public class BinarytreeDemo{
public static void main(String args[]){
System.out.println(new BTreeDemo().Start());
}
}

class BTreeDemo {

public int Start(){
Tree root;
boolean bool;
int nti;

root = new Tree();
bool = root.Init(16);
bool = root.Print();
System.out.println(100);
bool = root.Print();
System.out.println("After Inserting data is! ");
bool = root.Insert(8);
bool = root.Insert(24);
bool = root.Insert(40);
bool = root.Insert(12);
bool = root.Insert(20);
bool = root.Insert(28);
bool = root.Insert(14);
bool = root.Insert(25);
bool = root.Insert(25);
bool = root.Print();

System.out.println("Search value is: " + root.Search(24));
System.out.println("Search value is: " + root.Search(12));
System.out.println("Search value is: " + root.Search(16));
System.out.println("Search value is: " + root.Search(50));
System.out.println("Search value is: " + root.Search(12));
System.out.println("Search value is: " + root.Search(25));
System.out.println("After deleting data! ");
bool = root.Delete(12);
bool = root.Delete(25);
bool = root.Print();
System.out.println(root.Search(12));
System.out.println("Delete value is: " + root.Delete(12));
System.out.println("Delete value is: " + root.Delete(25));
return 0 ;
}

}

November 23, 2008 at 10:31 PM

class Tree{
Tree left ;
Tree right;
int key ;
boolean has_left ;
boolean has_right ;
Tree my_null ;

// Initialize a node with a key value and no children
public boolean Init(int v_key){
key = v_key ;
has_left = false ;
has_right = false ;
return true ;
}

// Update the right child with rn
public boolean SetRight(Tree rn){
right = rn ;
return true ;
}

// Update the left child with ln
public boolean SetLeft(Tree ln){
left = ln ;
return true ;
}

public Tree GetRight(){
return right ;
}

public Tree GetLeft(){
return left;
}

public int GetKey(){
return key ;
}

public boolean SetKey(int v_key){
key = v_key ;
return true ;
}

public boolean GetHas_Right(){
return has_right ;
}

public boolean GetHas_Left(){
return has_left ;
}

public boolean SetHas_Left(boolean val){
has_left = val ;
return true ;
}

public boolean SetHas_Right(boolean val){
has_right = val ;
return true ;
}

// This method compares two integers and returns true if they are equal and false

public boolean Compare(int num1 , int num2){
boolean bool ;
int nti ;

bool = false ;
nti = num2 + 1 ;
if (num1 < num2) bool = false ;
else if (!(num1 < nti)) bool = false ;
else bool = true ;
return bool ;
}
// Insert a new element in the tree
public boolean Insert(int v_key){
Tree new_node ;
boolean bool ;
boolean cont ;
int keyValue ;
Tree cNode ;

new_node = new Tree();
bool = new_node.Init(v_key) ;
cNode = this ;
cont = true ;
while (cont){
keyValue = cNode.GetKey();
if (v_key < keyValue){
if (cNode.GetHas_Left())
cNode = cNode.GetLeft() ;
else {
cont = false ;
bool = cNode.SetHas_Left(true);
bool = cNode.SetLeft(new_node);
}
}
else{
if (cNode.GetHas_Right())
cNode = cNode.GetRight() ;
else {
cont = false ;
bool = cNode.SetHas_Right(true);
bool = cNode.SetRight(new_node);
}
}
}
return true ;
}

// Delete an element from the tree

public boolean Delete(int v_key){
Tree cNode ;
Tree parent_node ;
boolean cont ;
boolean found ;
boolean is_root ;
int keyValue ;
boolean bool ;

cNode = this ;
parent_node = this ;
cont = true ;
found = false ;
is_root = true ;
while (cont){
keyValue = cNode.GetKey();
if (v_key < keyValue)
if (cNode.GetHas_Left()){
parent_node = cNode ;
cNode = cNode.GetLeft() ;
}
else cont = false ;
else
if (keyValue < v_key)
if (cNode.GetHas_Right()){
parent_node = cNode ;
cNode = cNode.GetRight() ;
}
else cont = false ;
else {
if (is_root)
if ((!cNode.GetHas_Right()) &&
(!cNode.GetHas_Left()) )
bool = true ;
else
bool = this.Remove(parent_node,cNode);
else bool = this.Remove(parent_node,cNode);
found = true ;
cont = false ;
}
is_root = false ;
}
return found ;
}

November 23, 2008 at 10:31 PM

// Check if the element to be removed will use the, righ or left subtree if one exists

public boolean Remove(Tree p_node, Tree c_node){
boolean bool ;
int auxkey1 ;
int auxkey2 ;

if (c_node.GetHas_Left())
bool = this.RemoveLeft(p_node,c_node) ;
else
if (c_node.GetHas_Right())
bool = this.RemoveRight(p_node,c_node) ;
else {
auxkey1 = c_node.GetKey();
auxkey2 = (p_node.GetLeft()).GetKey() ;
if (this.Compare(auxkey1,auxkey2)) {
bool = p_node.SetLeft(my_null);
bool = p_node.SetHas_Left(false);
}
else {
bool = p_node.SetRight(my_null);
bool = p_node.SetHas_Right(false);
}
}
return true ;
}

public boolean RemoveRight(Tree p_node, Tree c_node){
boolean bool ;

while (c_node.GetHas_Right()){
bool = c_node.SetKey((c_node.GetRight()).GetKey());
p_node = c_node;
c_node = c_node.GetRight() ;
}
bool = p_node.SetRight(my_null);
bool = p_node.SetHas_Right(false);
return true ;
}

public boolean RemoveLeft(Tree p_node, Tree c_node){
boolean bool;

while (c_node.GetHas_Left()){
bool = c_node.SetKey((c_node.GetLeft()).GetKey());
p_node = c_node ;
c_node = c_node.GetLeft() ;
}
bool = p_node.SetLeft(my_null);
bool = p_node.SetHas_Left(false);
return true ;
}
// Search for an elemnt in the tree
public int Search(int v_key){
boolean cont ;
int ifound ;
Tree cNode;
int keyValue ;

cNode = this ;
cont = true ;
ifound = 0 ;
while(cont){
keyValue = cNode.GetKey();
if (v_key < keyValue)
if (cNode.GetHas_Left())
cNode = cNode.GetLeft() ;
else cont = false ;
else
if (keyValue < v_key)
if (cNode.GetHas_Right())
cNode = cNode.GetRight() ;
else cont = false ;
else {
ifound = 1 ;
cont = false ;
}
}
return ifound ;
}

// Invoke the method to really print the tree elements
public boolean Print(){
Tree cNode;
boolean bool ;

cNode = this ;
bool = this.RecPrint(cNode);
return true ;
}

// Print the elements of the tree
public boolean RecPrint(Tree node){
boolean bool ;

if (node.GetHas_Left()){
bool = this.RecPrint(node.GetLeft());
} else bool = true ;
System.out.println(node.GetKey());
if (node.GetHas_Right()){
bool = this.RecPrint(node.GetRight());
}
else bool = true ;
return true ;
}
}

November 23, 2008 at 10:34 PM

For more information On Java visit to :

http://www.roseindia.net/java

Thanks


November 25, 2008 at 7:12 AM

Thanks alot for help, But how i can create the required records (DB) and GUI, and how i can visualise the tree and the result..

November 26, 2008 at 6:45 AM

please it is urgent... :(
who can help me?









Related Tutorials/Questions & Answers:
deletion in b plus tree
deletion in b plus tree  please help me out!! i need a code for deletion on b-plus tree in JAVA. its urgent please help
B+ tree - Java Beginners
. In this assignment, you will implement B+-tree data structure on a fixed-length data... field is separated or delimited by a white space. Initially, your B+-tree... user interface (GUI). Your GUI also visualizes B+tree structure after executing any
Advertisements
B+tree lodaing - Java Beginners
B+tree lodaing  hi, i have fixed-length data file such student table. All fields are fixed length: 8 for number (20022509), 3 for name (PIS), 4... or delimited by a white space. how i can Initially, constructed B+ tree based
initializing B+ tree from Jtable - JDBC
initializing B+ tree from Jtable   hi, i have fixed-length data file such student table.i stored this file in Jtable All fields are fixed length: 8... i can Initially, constructed B+ tree based from this Jtable. and make initial
Creating Database using B+Tree in Java - Java Beginners
Creating Database using B+Tree in Java  I'm doing a project in which I have to create an Object Oriented Database using B+Tree in Java... Node(25); System.out.println("Building tree with root value
B+ tree JAVA source code for implementing Insertion and Deletion - Java Beginners
B+ tree JAVA source code for implementing Insertion and Deletion  Can anyone plz mail de B+ tree JAVA source code for implementing Insertion...().Start()); } } class BTreeDemo { public int Start(){ Tree
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
the value of $$b
the value of $$b  If the variable $a is equal to 5 and variable $b is equal to character a, what?s the value of $$b
what is the value of $$b?
what is the value of $$b?  If the variable $a is equal to 5 and variable $b is equal to character a, what?s the value of $$b
what?s the value of $$b?
what?s the value of $$b?  If the variable $a is equal to 5 and variable $b is equal to character a, what?s the value of $$b
b+ trees - UML
b+ trees  can i get entire documentation of b+ trees implementation in java
b+trees - UML
b+trees  i need use case diagrams,class diagrams and flowcharts for b+ trees urgently
ModuleNotFoundError: No module named 'b'
ModuleNotFoundError: No module named 'b'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'b' How to remove the ModuleNotFoundError: No module named 'b' error
B+ trees search
B+ trees search  Can anyone send the code for implementing the B+ trees searching on a oracle database? please your answer will be useful for my project
B+ trees search
B+ trees search  Can anyone send the code for implementing the B+ trees searching on a oracle database? please your answer will be useful for my project
Binary tree
Binary tree  a. Construct a method to implement a binary tree using an array. b. Implement the binary tree to store numbers in sorted order
difference b/w == and equals()
difference b/w == and equals()  what is the difference between == operator and equals()   Hi Friend, The == operator checks if the two objects were actually the same object. This operator looks at the actually memory
b+trees - Swing AWT
b+trees  i urgently need source code of b+trees in java(swings/frames... model; public static TreePath path; public static JTree tree; public..."); DefaultMutableTreeNode tr = new DefaultMutableTreeNode("Tree"); DefaultMutableTreeNode
ModuleNotFoundError: No module named 'b-cbinterface'
ModuleNotFoundError: No module named 'b-cbinterface'  Hi, My... 'b-cbinterface' How to remove the ModuleNotFoundError: No module named 'b-cbinterface' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lib-b'
ModuleNotFoundError: No module named 'lib-b'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'lib-b' How to remove the ModuleNotFoundError: No module named 'lib-b'
ModuleNotFoundError: No module named 'pipfail_b'
ModuleNotFoundError: No module named 'pipfail_b'  Hi, My Python... 'pipfail_b' How to remove the ModuleNotFoundError: No module named 'pipfail_b' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'sketch_b'
ModuleNotFoundError: No module named 'sketch_b'  Hi, My Python... 'sketch_b' How to remove the ModuleNotFoundError: No module named 'sketch_b... to install padas library. You can install sketch_b python with following
ModuleNotFoundError: No module named 'b-cbinterface'
ModuleNotFoundError: No module named 'b-cbinterface'  Hi, My... 'b-cbinterface' How to remove the ModuleNotFoundError: No module named 'b-cbinterface' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'b-dist'
ModuleNotFoundError: No module named 'b-dist'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'b-dist' How to remove the ModuleNotFoundError: No module named 'b-dist'
ModuleNotFoundError: No module named 'b-logcat'
ModuleNotFoundError: No module named 'b-logcat'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'b-logcat' How to remove the ModuleNotFoundError: No module named 'b-logcat
ModuleNotFoundError: No module named 'B_pp'
ModuleNotFoundError: No module named 'B_pp'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'B_pp' How to remove the ModuleNotFoundError: No module named 'B_pp' error
ModuleNotFoundError: No module named 'b-rabbit'
ModuleNotFoundError: No module named 'b-rabbit'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'b-rabbit' How to remove the ModuleNotFoundError: No module named 'b-rabbit
Diff b\w C++ & Java
Diff b\w C++ & Java  What is the difference between C++ & Java
Version of com.intropro>B-test dependency
List of Version of com.intropro>B-test dependency
difference b/w viewdidload and ViewWillAppear
difference b/w viewdidload and ViewWillAppear   hello all, what is the difference b/w viewdidload and ViewWillAppear ???   hello,ADS_TO_REPLACE_1 when view is loaded then this method run one time but ViewWillAppear
tree
How to design a tree, design a tree, a tree
Tool (P key) to make a tree shape. Brush Tool: Choose Brush Tool (B key... How to design a tree       Be alert to learn a simple technique to make a tree example
b tech course in artificial intelligence
b tech course in artificial intelligence  Hi, I am beginner in Data...: b tech course in artificial intelligence Try to provide me good examples or tutorials links so that I can learn the topic "b tech course in artificial
b tech artificial intelligence colleges
b tech artificial intelligence colleges  Hi, I am beginner in Data...: b tech artificial intelligence colleges Try to provide me good examples or tutorials links so that I can learn the topic "b tech artificial
artificial intelligence b tech course
artificial intelligence b tech course  Hi, I am beginner in Data...: artificial intelligence b tech course Try to provide me good examples or tutorials links so that I can learn the topic "artificial intelligence b tech
diff b/w applet and servlet
diff b/w applet and servlet  what is the difference between applet and servlet?   Difference between servlet and applet: 1)An applet is client side programming whereas servlet is server side programming. 2)Applets run
demonstrate a) static data members b) static methods
demonstrate a) static data members b) static methods  demonstrate a) static data members b) static methods
Difference b/w spring 2.x and 3.x
Difference b/w spring 2.x and 3.x  difference b/w spring 2.x and 3.x
diff b/w struts 1.0 and 1.2
diff b/w struts 1.0 and 1.2  diff b/w struts 1.0 and 1.2
tree view
tree view  display a tree view in flex?nodes will be in the form
Spanning Tree
Spanning Tree  hii, What is a spanning Tree?   hello,ADS_TO_REPLACE_1 A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree
binary tree
binary tree  how to count no. of nodes in a binary tree for mlm if it complet tree or incomplet tree in php using mysql db
Binary tree
Binary tree  hii, What is binary tree?   hello,ADS_TO_REPLACE_1 A binary tree is a tree in which every node has exactly two links i.e left and right link
binary tree
binary tree  can a binary tree be implemented with out comparing...://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml
FLex Tree
FLex Tree  I want to change the node name in flex tree my code is: Company:XML = <Element name ="Element" code="400"> <{newChild} name ={newChild1} code="400"/> ; where comapny is dataprovide for tree. I want
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three condition such as x<5,5<=x<10 and 10<=x<15 after that we have
Nitobi Tree
Nitobi Tree       Nitobi Tree Nitobi Tree, the Ajax component of User Interface Suite is used... coding and effort. Nitobi Tree adds just like folder view in Windows
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root

Ads