Download Representation Tree Structures by Dynamic Lists

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Linked list wikipedia , lookup

Quadtree wikipedia , lookup

Lattice model (finance) wikipedia , lookup

Red–black tree wikipedia , lookup

B-tree wikipedia , lookup

Interval tree wikipedia , lookup

Binary tree wikipedia , lookup

Binary search tree wikipedia , lookup

Transcript
T.A. Ramirez Romero, et al International Journal of Computer and Electronics Research [Volume 3, Issue 4, August 2014]
Representation Tree Structures by Dynamic Lists
TonahtiuArturo Ramírez Romero1, Gumersindo David Fariña López2, Miguel Patiño Ortiz3.
1
Instituto Politécnico Nacional, México
2
Centro de Estudios Científicos y Tecnológicos No.7, IPN, D.F. México
3
Escuela Superior de Ingeniería Mecánica y Eléctrica unidad Zacatenco, IPN, D.F. México
Abstract–This article shows an idea ofrepresentation of tree
structures using simply linked lists in language C++, although it
is possible to develop more sophisticated ideas to create a range
of possibilities, the idea of this paper is to present a simple idea
that can be taken to other developments.
In Figure 1, a graphical representation of one of these
structures is shown.
Keywords: Data structures, tree structure, Dynamic lists.
I. INTRODUCTION
Had long been working on the development of structures
for store and retrieve data, derived from these studies has
been created structures of various kinds, for example simply
link lists, doubly linked lists, circular lists, trees, graphs, and
some other structures, in this work orientation is toward the
trees, their use facilitates knowledge representation.
To store the tree’s structures without a doubt there are
several tools, but here is show that simply using C++
language can create a simple handler to create and operate
dynamic trees and send to memory storage device if is
necessaryfor later use.
Data structures called trees based his idea on real trees,
which consist of a root, stem, branches and leaves, the only
difference is that usually these structures are plotted in
reverse or in other words is broken the shaft 180 °, but you
have to note that the plot is just that one modeling so to terms
of storage and use no matter how it is displayed.Below we
show a definition of trees and his elements.
There are different kinds of trees, binary, red-black, B[4],
in this paper we use a general tree.
II. DEFINITIONS.
Before beginning, give a brief description of terms used.
Tree: Is a nonlinear two-dimensional structure and consists
of a finite set of one or more elements (called nodes, etc.) as
root, nodes, branches, and grade levels. There is a specially
designated node called root.The remaining nodes are
partitioned into n >=0 disjoint sets N1, N2, N3, N4, …,Nn
where N1, N2, N3, N4, …,Nn are called the sub-trees of the
root. [1]
Trees are defined in graph theory as connected acyclic
graph. Therefore any two tree nodes are connected by a
unique path a tree is a set of nodes connected with edges. One
node called root, has not incoming edges and one or more
outgoings edges. The remaining nodes are partitioned in
independent sets, each one being another tree. This recursive
definition shows that recursion techniques may be widely
used in tree processing.
Nodes with incoming edges from another node are called
children of the edge source, which is an analogous manner is
called the father or parent node. With a similar reasoning the
terms ancestor, descendant. The number of children of a node
is a node degree. [2].
©http://ijcer.org
e- ISSN: 2278-5795
Figure 1: A graphical tree representation
Root: This is the first node or above another and did not. This
can be derived from other nodes which can be called child
nodes.
Branches: Targeted lines are called branches (as the truth
tree).
Level:. The level of a node is its distance to the root. The root
has zero distance from itself, so it is said that the root is at
level zero - 0. The children at level - 1 and their children at
level -2 and their children's children in level -3 and so on.
Road or path: Is the sequence of nodes that are still to reach
a certain node to another in which each node is adjacent to
the next. So regulate a road or path is traced from the root to
a leaf, can is the source or root sheet.
Height or depth of a tree is the leaf level or longer road
route from the root plus (+), one
In Figure 2, these items are shown in a tree data structure.
Figure 2: Tree’s element
p- ISSN: 2320-9348
Page 181
T.A. Ramirez Romero, et al International Journal of Computer and Electronics Research [Volume 3, Issue 4, August 2014]
If branches are observed can be seen that said branches
have arrows broadly indicate only that the stops could be in
that direction, although it should be clear that depending on
the implementation of the tree structure may be bidirectional.
One can say that these branches only indicate direct
relationship between those nodes.
List simply linked. A linked representation of data
structure known as a linked list is a collection of nodes. Each
Node is a collection of fields categorized as data items and
links. He data items fields holds the information content or
data to be represented by the node. The link fields hold the
address of the neighboring nodes or of those nodes which are
associated with the given node as dictated by application. [3].
C++ is a high level language, allowing compiling source
programs and making them executable. (Savitch, 2007)
It has presented the basics of the trees, but still lacks the
most important, what can be stored? How can you
implement?
What are they?
Hereinafter structures of the trees will be called only trees.
The trees have applications in various areas such as:
Design Compiler, expert systems, evolutionary systems,
conscious systems, management such directories index
databases and much more.
No place has many applications, but its implementation is
not as widely used as the traditional database, but currently
there are models by which a tree can be represented in a
purely dynamic or doubly linked list, this model will be
presented later.
What can you store?
If trees are implanted in dynamic data structures, can
contain as required, but can also be implemented in static
arrays, in dynamic data structures can store objects or
pointers.
III. DEVELOMPMENT
How you can implement?
There are many way to represent tree structures as ideas
emerge, now we proceed with a simple proposal to manage
trees of various levels and degrees, implementation on a
simply linked list structure is shown below.
The idea is that the user to capture data indicating the
parent node and the data node or objects themselves, and
these are stored in a simply linked list that is linear and that
models a tree that is not linear.
These operations to be in RAM memory are very fast, and
if the user requires can be saved to disk or other media.
For example if the C++ language is used and opt for
dynamic structures especially for the single linked list, you
can define an object called node as follows:
class node
{
public:
//Code to operate trees
intId_father, Id;
node*next;
// Data into the node
obj data;
©http://ijcer.org
};
If want to use double linked list is very similar as you can
see below.
class node
{
public:
//Code to operate trees
int Id_father, Id;
node *prev,*next;
// Data into the node
obj data;
};
As seen in the previous program data of type obj can
define any type and amount of data required or other objects.
Therefore it can be adapted perfectly to the needs of the
problem.
The proposed node is presented in figure 3.
Figure 3: Proposed Node
As seen in figure 3. The node for simply linked list is
divided into three sections, first with data *ptr_next is to
store the physical address of the next node, is used to
construct the dynamic list, the second sections allow integer
data types id and id_father, id is a unique identifier for this
node, and id_father is a identifier of his ancestor or father, is
used to model a tree’s structure, the third section allow object
for information of the user.
Now a structure of tree is presented in a list simply linked
in figure 4.
Figure 4: List simply linked
Further to be noted a nonlinear structure (tree) becomes a
linear structure (list), this proposal is easy to implement.
In the figure 5 shown a graphical example, how to work
this proposal.
e- ISSN: 2278-5795
p- ISSN: 2320-9348
Page 182
T.A. Ramirez Romero, et al International Journal of Computer and Electronics Research [Volume 3, Issue 4, August 2014]
else
{
ptr_aux=new (node);
ptr_aux->data=data;
ptr_aux->sig=ptr_aux;
ptr_main->sig=ptr_aux;
ptr_main = ptr_aux;
}
Now the function that allows you to find data structure is
presented (Search)
Figure 4: Tree modeled into list
Each node has two ids one from itself and other from the
ancestor or father. This configuration allow that a father have
n descendants or sons, and a node only one father or ancestor.
To implement this proposal is necessary at least three
functions:
 Insert
 Search
 List
Below the minimum code of the above functions are
presented in simply list linked.
void list_tree::Search(obj data)
{int flag=0;
if(ptr_ini <> NULL)
{
ptr_aux = ptr_ini;
do
{
if(ptr_aux->data <> data)
ptr_aux = ptr_aux ->sig;
else
{
flag = 1;
cout<< “The value is: “ -> ptr_aux->data; //note 1
}
} while (ptr_aux <> ptr_aux->sig && !flag)
}
else
cout<< “Empty tree”;
if(!flag)
cout << “Don’t find it node”;
}
First the object class list_tree.
Check the note 1 on last program fragment, in this line we
consider only show in screen the value of data, but if consider
you can change the code, to retrieve the node address, or do
other action.
Finally the function List, it’s only show the nodes in list
form, but with more work can show a tree, but maybe is
necessary a graphical ambient.
typedef node *ptr_node;
class list_tree
{
public:
ptr_node ptr_ini, ptr_aux, ptr_main;
list_tree()
{ptr_ini=NULL;
ptr_aux=NULL;
ptr_main=NULL;
}
…
}
Now main functions are presented.
void list_tree::Insert(obj data, int id, int id_father)
{
if (ptr_ini==NULL)
{
ptr_ini=new (node);
ptr_ini->data=data;
ptr_ini->sig=ptr_ini;
ptr_main=ptr_ini;
}
©http://ijcer.org
e- ISSN: 2278-5795
void list_tree::List(void)
{
if(ptr_ini <> NULL)
{
ptr_aux = ptr_ini;
do
{
cout<< “The value is: “ -> ptr_aux->data;
} while (ptr_aux <> ptr_aux->sig)
}
else
cout<< “Empty tree”;
}
The functions listed here are the most essential and can be
adapted to the particular needs of the users.
p- ISSN: 2320-9348
Page 183
T.A. Ramirez Romero, et al International Journal of Computer and Electronics Research [Volume 3, Issue 4, August 2014]
IV. CONCLUSIONS
It is noteworthy that the proposal presented here is in the
first instance to reduce the complexity of managing tree, to
transform its non-linear to a linear form, and the respective
adjustments to the search criteria will be able to solve various
problems.
Although only three functions here is should think the
deletion of nodes integrally or as known in the environment
pruning of branches is left for future work.
It is necessary build the function to save the data to
another permanent storage media.
ACKNOWLEDGMENT
We like to express sincere appreciation and deep gratitude
to all participants in this work
REFERENCES
[1] Neeta Deshpande, S.S. Sane Pune, “Data structures and
files”, Ed. Technical publications, India.2007.
[2] Allen Kent, James G. Williams, “Encyclopedia of
computer science and Technology. AerosPate
Application of artificial intelligence to Tree Structures”,
Ed. CRC Press, 1993. USA.
[3] Gavpai, “Data Structures and Algorithms, concepts,
techniques and Applications”, Second reprint, P.P. 86,
Tata McGraw-Hill, India, 2008.
[4] Debasy Samantha, “Classic Data Structures”, Second
edition, Ed. Easter Economy Edition, India, 2009.
[5] Walter Savitch, “Resolución de problemas en C++”,
Quinta edición, Ed. Pearson educación, México, 2007.
©http://ijcer.org
e- ISSN: 2278-5795
p- ISSN: 2320-9348
Page 184