Google Answers Logo
View Question
 
Q: Simple B-Tree Implementation in Java ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Simple B-Tree Implementation in Java
Category: Computers > Programming
Asked by: buckdharma-ga
List Price: $55.00
Posted: 18 Apr 2005 11:34 PDT
Expires: 18 May 2005 11:34 PDT
Question ID: 510893
Greetings,

I've been working for a while on a pretty simple B-Tree implementation
in Java...but my life just went crazy and I need a little help. I'm
certainly not asking for source code that I can just pop in and have
it work magically. All I need is some nicely written, Java/Object
Oriented pseudocode. So, I'd really appreciate a hand. I promise to
tip honorably according to how much I've been helped. :) If you feel
I'm not offering enough, just tell me, I'm new to this kind of thing.
It's OK if you copy + paste from another site as long as I have the
reference.

Here's the requirements:
It's written in java. One can use any class from the API they need to
(I know there's some TreeMaps and whatnot in the API). The B-tree is a
standard M-ary tree of size M=5 with these properties (taken from a
textbook):

1. Data can be stored at any level (not just the leaves). They data is
the same as the keyvalue - an int between 1 an 99 (including them).
2. The nonleaf nodes store as many as M-1 keys to guide the searching;
key i represents the smallest key in subtree i+1.
3.  The root is either a leaf or has between 2 and M children.
4. All nonleaf nodes (Except the root) have between at most M/2 and M children.

The data we input will be no more than enough to make 3 levels of the tree.

Now, here's what the program needs to be able to do:
A. Draw the tree, vertically (as in, root node grows down from the
center top of the screen). Just using ASCII text (I code on a Linux
text console).
B. Delete a node at a given integer.
C. Insert a given integer into the tree.
D. Locate a given int and indicate a success/fail message
E. Find the depth of any data item or report failure.

That's it! Nothing really complex or fancy -- just your average B-tree.

I need this no later than the afternoon of Thursday (the 21st). Of
course, I'll tip more if I get something earlier :P

I greatly, sincerely appreciate your help.

Clarification of Question by buckdharma-ga on 18 Apr 2005 11:36 PDT
And I'm just using this space to emphasize that it's yes, THIS
Thursday. I'm sorry for the short notice. I really appreciate your
help.

Request for Question Clarification by studboy-ga on 18 Apr 2005 14:20 PDT
Hi buckdharma-ga

Please take a look at the following two references:

1) A very good algorithm description and implementation in C++:
http://cis.stvincent.edu/swd/btree/btree.html

2) An implementation in Java (this pretty much does what you need in A, B, C--
D, E can be easily done by modifying the search function):
http://www.hta-bi.bfh.ch/~ctr/archive/project1/BTree1/description/btreedocu.htm
(download the zip file at end end: it contains the source AND tes codes).

3) Another algorithm description and example:
http://bluerwhite.org/btree/

4) Java applet demos:
http://www.geocities.com/SiliconValley/Program/2864/File/btree.html
http://sky.fit.qut.edu.au/~maire/baobab/baobab.html


Let me know if this serves your needs and I can post a formal answer.

Thanks
studboy-ga

Request for Question Clarification by studboy-ga on 18 Apr 2005 15:47 PDT
Also note that the Java collection support (TreeMap) is for Red-Black
(binary) tree--not for the generalized B(Balanced)-tree you need. 
That's why the codes in my references have to specifically implement
the B-tree.

Clarification of Question by buckdharma-ga on 18 Apr 2005 16:15 PDT
Oh, wow, that was fast. I can't look at the entirety of the source
code, but it looks very solid. Go ahead and post as answered, and in
the mean time see if you can dig up any more stuff :)
Answer  
Subject: Re: Simple B-Tree Implementation in Java
Answered By: studboy-ga on 19 Apr 2005 01:04 PDT
Rated:5 out of 5 stars
 
Thanks buckdharma-ga.  It's been a pleasure helping you.  In summary,
the following references may be able to help you with B-tree
implementation in Java:

1) A very good algorithm description and implementation in C++:
http://cis.stvincent.edu/swd/btree/btree.html

2) An implementation in Java (this pretty much does what you need in A, B, C--
D, E can be easily done by modifying the search function):
http://www.hta-bi.bfh.ch/~ctr/archive/project1/BTree1/description/btreedocu.htm
(download the zip file at end end: it contains the source AND tes codes).

3) Another algorithm description and example:
http://bluerwhite.org/btree/

4) Java applet demos:
http://www.geocities.com/SiliconValley/Program/2864/File/btree.html
http://sky.fit.qut.edu.au/~maire/baobab/baobab.html

Also note that the Java collection support (TreeMap) is for Red-Black
(binary) tree--not for the generalized B(Balanced)-tree you need. 
That's why the codes in my references have to specifically implement
the B-tree.
 
Thanks and best regards,
studboy-ga
buckdharma-ga rated this answer:5 out of 5 stars and gave an additional tip of: $10.00
Awesome job! Very speedy. Thanks!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy