Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: 2-3-4 Tree (Btree)

  1. #1
    Junior Member
    Join Date
    Sep 2009
    My Mood
    Thanked 3 Times in 3 Posts

    Default 2-3-4 Tree (Btree)

    Hello JPF.

    I am currently trying to implement a 2-3-4 tree for my class. Pseudocodes are provided for the methods that I am to write codes for, but I am still unclear as how to set this up. This is what I have so far:

    import java.util.*;
    public class TwoThreeFourTree
       protected static class Node 
         protected ArrayList<Integer> data;
         boolean isLeaf;
         /** Reference to the first, second, third, and fourth child */
         protected Node first;
         protected Node second;
         protected Node third;
         protected Node fourth;
         // Constructors
         /** Construct a node with given data and no children.
             @param data The data to store in this node
         public Node(ArrayList<Integer> data) 
           this.data = data;
           first = null;
           second = null;
           third = null;
           fourth = null;
         // Methods
         /** Return a string representation of the node.
             @return A string representation of the data fields
         public String toString() {
           return data.toString();
       private Node root;
        * Constructs a 2-3-4 tree.
       public TwoThreeFourTree()
       public String search(int n)
          search(root, n);
          return null;
       public String search(Node node, int n)
          int i=1;
          while(i<=node.data.size() && n>node.data.get(i))
          if (i<=node.data.size() && n==node.data.get(i))
             String s = new Integer(node.data.get(i)).toString();
             return s;
                return null;
                   return search(root.first, n);
                      return search (root.second, n);
                         return search (root.third, n);
                         if (i==4)
                            return search (root.fourth, n);
          return null;
       public void insert(int i)

    Am I going about this in the right direction? If not, please provide some suggestions.
    Last edited by vluong; April 4th, 2010 at 03:57 PM.

Similar Threads

  1. Data Structures(Binary Search Tree to AVL Tree)ASAP
    By jfAdik in forum Algorithms & Recursion
    Replies: 2
    Last Post: April 5th, 2010, 03:58 AM
  2. t:tree 2 an
    By smackdown90 in forum Web Frameworks
    Replies: 0
    Last Post: January 27th, 2010, 12:56 PM
  3. B+ Tree
    By mikesir87 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 20th, 2009, 10:52 AM
  4. B+ Tree implementation
    By programmer in forum Java Theory & Questions
    Replies: 2
    Last Post: November 15th, 2009, 05:47 PM
  5. Binary Search Tree
    By Koren3 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 12th, 2009, 09:27 AM