Tree structure, Data Structure & Algorithms

We would like to implement a 2-4Tree containing distinct integer keys. This 2-4Tree is defined by the ArrayList Nodes of all the 2-4Nodes in the tree and the special 2-4Node Root which is the root of the tree. Each 2-4Node is defined by 2 ArrayLists Keys and Refs. Keys is an ArrayList of Integer objects representing the ordered integer keys stored in the node;

Refs is an ArrayList containing the references to the node's parent (NULL if the node is the root) and children (NULL if they are leaves). All these ArrayLists are implemented in java.util.ArrayList. Implement the following methods of the two classes 2-4Node and 2-4Tree using the methods of java.util.ArrayList as well as any other method you find necessary:


{ public int Type(): Returns the type of the node (2Node or 3Node etc.). { public void InsertinNode(int i): Inserts the integer i in the node at the right position. We consider that the children of the node are leaves. The Keys and Refs lists should be appended properly. Thus, you have to take into account the special case where the node contains no keys. No duplicate keys are allowed in the node so this method returns an error if you try to insert an existing key.

On the other hand an overow is not treated in this method.


{ public 2-4Node[] Search(int i,2-4Node N): This method searches recursively for the key i in the 2-4subtree of root N. It returns a reference to the node M containing i (NULL if i is not in the subtree) and another reference to the parent of this node M (if M is NULL its parent is the last searched 2-4node). Returns an error if N is NULL.

{ public void Insert(int i): Inserts the key i in the 2-4Tree at the right 2- 4Node and position. You have to take into account the special case where i is the first key to be inserted in the 2-4Tree. Returns an error if i is already in the 2-4Tree. In the case of an overow this overow should be treated!

{ public void split(2-4Node N): Splits the overowing 2-4Node N into two separate nodes and sends the 3rd key in N to its parent M. The lists Keys and Refs of M should be modified properly. The split is applied to the parent M if overowing etc. Pay attention to the special case where N is the root of the 2-4Tree.

Test :

Test your classes and methods by inserting the following sequence of integers (in the same order) into an initially empty 2-4Tree:f8,12,1,15,2,14,3,10,5,6,4,9,16,21,7,17g. Printout the keys in the 2-4 Node M containing 6, the keys in its parent and in the 2nd child of M.

Posted Date: 2/22/2013 1:51:15 AM | Location : United States

Related Discussions:- Tree structure, Assignment Help, Ask Question on Tree structure, Get Answer, Expert's Help, Tree structure Discussions

Write discussion on Tree structure
Your posts are moderated
Related Questions
Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

How sparse matrix stored in the memory of a computer?

A binary tree of depth "d" is an almost complete binary tree if  A) Every leaf in the tree is either at level "d" or at level "d-1"  B)  For any node "n" in the tree with a

Write a program to simulate searching over a hashed file, with different assumptions for the sizeof file pages.Write a program to perform equality search operations on the hashed f

Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

nested for loop for (i = 0; i for (j = 0; j sequence of statements } } Here, we observe that, the outer loop executes n times. Every time the outer loop execute

Given are the definitions of some important terms: 1) Field: This is an elementary data item characterized by its size, length and type. For instance, Name

Ask question #Minima binary search tree is used to locate the number 43 which of the following probe sequences are possible and which are not? explainum 100 words accepted#

Program Insertion of a node into any Circular Linked List Figure depicts a Circular linked list from which an element was deleted. ALGORITHM (Deletion of an element from a

Your objective is to write a generic doubly linked list class called CS228LinkedList that implements the List interface and uses a type variable T. All methods except for subList a