Universidad Nacional Mayor de San Marcos Facultad de Ingeniera de Sistemas e Informtica Escuela de Ingeniera de Software Asignatura: Estructuras de Datos II Preparado por: Juan Gamarra Moreno
rboles
Un rbol es una estructura no lineal cuyos elementos estn organizados en jerarqua Un rbol es descrito por un conjunto grande de trminos relacionados
rboles
Longitud de camino y Nivel La longitud de camino se determina al contar el nmero de aristas que se deben seguir para llegar desde la raz al nodo
La altura de un rbol es la longitud del camino ms largo desde la raz hasta la hoja
rboles
Clasificacin de rboles
The most important criterion is the maximum number of children any node in the tree may have. This value is sometimes referred to as the order of the tree.
rboles
Clasificacin de rboles
A tree that has no limit to the number of children a node may have is called a general tree. A tree that limits each node to no more than n children is referred to as an n-ary tree
rboles
Clasificacin de rboles
A tree in which nodes may have at most two children is called a binary tree.
rboles
Clasificacin de rboles
A tree is considered to be balanced if all of the leaves of the tree are on the same level or at least within one level of each other.
rboles
Clasificacin de rboles
A balanced n-ary tree with m elements will have a height of lognm. Thus a balanced binary tree with n nodes will have a height of log2n.
rboles
Clasificacin de rboles
A balanced n-ary tree with m elements will have a height of lognm. Thus a balanced binary tree with n nodes will have a height of log2n.
rboles
Clasificacin de rboles
A tree is considered complete if it is balanced and all of the leaves at the bottom level are on the left side of the tree.
10
rboles
Clasificacin de rboles
Another related concept is the notion of a full tree. An n-ary tree is considered full if all the leaves of the tree are at the same level and every node is either a leaf or has exactly n children.
11
The most obvious implementation of a tree is a linked structure. Each node could be defined as a TreeNode class. Each node would contain a pointer to the element to be stored in that node as well as pointers for each of the possible children of the node.
12
It may also be useful for each node to store a pointer to its parent. This use of pointers is similar to the concept of a doubly linked list. The strategies for array implementations of a tree may be less obvious.
13
One possible computational strategy places the left child of element n at position (2 * n + 1) and the right child at position (2 * (n + 1)).
14
The simulated link strategy allows array positions to be allocated contiguously regardless of the completeness of the tree.
El orden de entrada es A, C, B, E, D, F
15
Recorrido de rboles
Recorridos Preorder traversal, which is accomplished by visiting each node, followed by its children, starting with the root Inorder traversal, which is accomplished by visiting the left child of the node, then the node, then any remaining nodes, starting with the root Postorder traversal, which is accomplished by visiting the children, then the node, starting with the root Level-order traversal, which is accomplished by visiting all of the nodes at each level, one level at a time, starting with the root
16
Recorrido de rboles
Recorrido Preorder
Preorder traversal means visit the node, then the left child, then the right child.
Visit node Traverse(left child) Traverse(right child)
17
Recorrido de rboles
Recorrido Inorder
Inorder traversal means visit the left child, then the node, then the right child..
Traverse(left child) Visit node Traverse(right child)
18
Recorrido de rboles
Recorrido Postorder
Postorder traversal means visit the left child, then the right child, then the node.
Traverse(left child) Traverse(right child) Visit node
19
Recorrido de rboles
Recorrido Level-Order
Level-order traversal means visit the nodes at each level, one level at a time, starting with the root.
Traverse(left child) Traverse(right child) Visit node
20
Muchas Gracias
21