You are on page 1of 12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

Tree traversal
From Wikipedia, the free encyclopedia

In computer science, tree traversal refers to the process of visiting (examining and/or updating) each node in a tree data structure, exactly once, in a systematic way. Such traversals are classified by the order in which the nodes are visited. The following algorithms are described for a binary tree, but they may be generalized to other trees as well.

Contents
1 Traversals 1.1 Depth-first traversal 1.2 Breadth-first traversal 2 Example 3 Infinite trees 4 Implementations 4.1 Queue-based level order traversal 4.2 Uses 4.3 Functional traversal 4.4 Iterative Traversal 4.5 Recursive Traversals in C 4.5.1 Inorder Traversal 4.5.2 Preorder Traversal 4.5.3 Postorder Traversal 5 References 6 External links

Traversals
Compared to linear data structures like linked lists and one dimensional arrays, which have a canonical method of traversal (namely in linear order), tree structures can be traversed in many different ways. Starting at the root of a binary tree, there are three main steps that can be performed and the order in which they are performed defines the traversal type. These steps (in no particular order) are: performing an action on the current node (referred to as "visiting" the node), traversing to the left child node, and traversing to the right child node. Traversing a tree involves iterating (looping) over all nodes in some manner. Because from a given node there is more than one possible next node (it is not a linear data structure), then, assuming sequential computation (not parallel), some nodes must be deferred stored in some way for later visiting. This is often done via a stack (FILO) or queue (FIFO). As a tree is a self-referential (recursively defined) data structure, traversal can naturally be described by recursion or, more subtly, corecursion, in which case the deferred nodes are stored implicitly in the case of recursion, in the call stack. The name given to a particular style of traversal comes from the order in which nodes are visited. Most simply,
en.wikipedia.org/wiki/Tree_traversal 1/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

does one go down first (depth-first: first child, then grandchild before second child) or across first (breadth-first: first child, then second child before grandchildren)? Depth-first traversal is further classified by position of the root element with regard to the left and right nodes. Imagine that the left and right nodes are constant in space, then the root node could be placed to the left of the left node (pre-order), between the left and right node (in-order), or to the right of the right node (post-order). There is no equivalent variation in breadth-first traversal given ordering of children, "breadth-first" is unambiguous. For the purpose of illustration, it is assumed that left nodes always have priority over right nodes. This ordering can be reversed as long as the same ordering is assumed for all traversal methods. Depth-first traversal is easily implemented via a stack, including recursively (via the call stack), while breadth-first traversal is easily implemented via a queue, including corecursively. Beyond these basic traversals, various more complex or hybrid schemes are possible, such as depth-limited searchs such as iterative deepening depth-first search.

Depth-first traversal
See also: Depth-first search Binary Tree To traverse a non-empty binary tree in preorder, perform the following operations recursively at each node, starting with the root node[1]: 1. Visit the root. 2. Traverse the left subtree. 3. Traverse the right subtree. To traverse a non-empty binary tree in inorder (symmetric), perform the following operations recursively at each node[1]: 1. Traverse the left subtree. 2. Visit the root. 3. Traverse the right subtree. To traverse a non-empty binary tree in postorder, perform the following operations recursively at each node[1]: 1. Traverse the left subtree. 2. Traverse the right subtree. 3. Visit the root. Note that neither one sequentialisation according to pre-, in- or postorder describes the underlying tree uniquely; any combination of two different sequentialisations enables full reconstruction, though[2]. Generic Tree To traverse a non-empty tree in depth-first order, perform the following operations recursively at each node:
en.wikipedia.org/wiki/Tree_traversal 2/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

1. Perform pre-order operation 2. for i=1 to n-1 do 1. Visit child[i], if present 2. Perform in-order operation 3. Visit child[n], if present 4. Perform post-order operation where n is the number of child nodes. Depending on the problem at hand, the pre-order, in-order or post-order operations may be void, or you may only want to visit a specific child node, so these operations should be considered optional. Also, in practice more than one of pre-order, in-order and post-order operations may be required. For example, when inserting into a ternary tree, a pre-order operation is performed by comparing items. A post-order operation may be needed afterwards to rebalance the tree.

Breadth-first traversal
See also: Breadth-first search Trees can also be traversed in level-order, where we visit every node on a level before going to a lower level.

Example
Binary tree:

Depth-first Preorder traversal sequence: F, B, A, D, C, E, G, I, H (root, left, right) Inorder traversal sequence: A, B, C, D, E, F, G, H, I (left, root, right); note how this produces a sorted sequence Postorder traversal sequence: A, C, E, D, B, H, I, G, F (left, right, root) Breadth-first
en.wikipedia.org/wiki/Tree_traversal 3/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

Level-order traversal sequence: F, B, G, A, D, I, C, E, H pre-order in-order


p u s hFBA p o pA p o pB p u s hDC p o pC p o pD p u s hE p o pE p o pF p u s hG p o pG p u s hIH p o pH p o pI

post-order level-order
e n q u e u eF d e q u e u eF e n q u e u eBG d e q u e u eB e n q u e u eAD d e q u e u eG e n q u e u eI d e q u e u eA d e q u e u eD e n q u e u eCE d e q u e u eI e n q u e u eH d e q u e u eC d e q u e u eE d e q u e u eH

p u s hF p o pF p u s hBG p o pB p u s hADI p o pA p o pD p u s hCEH p o pC p o pE p o pG p o pI p o pH

p u s hFBA p o pA p u s hDC p o pC p u s hE p o pE p o pD p o pB p u s hGIH p o pH p o pI p o pG p o pF

Infinite trees
While tree traversal is generally done for finite trees finite number of nodes, hence finite depth and finite branching factor it can also be done for infinite trees. This is of particular interest in functional programming (particularly with lazy evaluation), as infinite data structures can often be easily defined and worked with, though they are not (strictly) evaluated, as this would take infinite time. More practically, some trees are, while finite, so large as to in practice be infinite, such as the game tree for chess or go, and thus analyzing them as if they were infinite is useful infinite trees are the limiting case of very large trees. A basic requirement for traversal is to visit every node. For infinite trees, simple algorithms often fail this. For example, given a binary tree of infinite depth, a depth-first traversal will go down one side (by convention the left side) of the tree, never visiting the rest, and indeed if in-order or post-order will never visit any nodes, as it has not reached a leaf (and in fact never will). By contrast, a breadth-first (level-order) traversal will traverse a binary tree of infinite depth without problem, and indeed will traverse any tree with bounded branching factor. On the other hand, given a tree of depth 2, where the root node has infinitely many children, and each of these children has two children, a depth-first traversal will visit all nodes, as once it exhausts the grandchildren (children of children of one node), it will move on to the next (assuming it is not post-order, in which case it never reaches the root). By contrast, a breadth-first traversal will never reach the grandchildren, as it seeks to exhaust the children first. A more sophisticated analysis of running time can be given via infinite ordinal numbers; for example, the breadthfirst traversal of the depth 2 tree above will take 2 steps: for the first level, and then another for the second level. Thus, simple depth-first or breadth-first searches do not traverse every infinite tree, and are not efficient on very large trees. However, hybrid methods can traverse any (countably) infinite tree, essentially via a diagonal argument (diagonal combination of vertical and horizontal corresponds to hybrid combination of depth and breadth). Concretely, given the infinitely branching tree of infinite depth, label the root node
en.wikipedia.org/wiki/Tree_traversal

the children of the root node


4/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

the grandchildren and so forth. The nodes are thus in a one-to-one correspondence with finite (possibly empty) sequences of positive numbers, which are countable and can be placed in order first by sum of entries, and then by lexicographic order within a given sum (only finitely many sequences sum to a given value, so all entries are reached formally there are a finite number of compositions of a given natural number, specifically 2n 1 compositions of n 1;), which gives a traversal. Explicitly:
0 :( ) 1 :( 1 ) 2 :( 1 , 1 )( 2 ) 3 :( 1 , 1 , 1 )( 1 , 2 )( 2 , 1 )( 3 ) 4 :( 1 , 1 , 1 , 1 )( 1 , 1 , 2 )( 1 , 2 , 1 )( 1 , 3 )( 2 , 1 , 1 )( 2 , 2 )( 3 , 1 )( 4 )

etc. This can be alternatively interpreted as mapping the infinite depth binary tree onto this tree and then applying breadth-first traversal: replace the "down" edges connecting a parent node to its second and later children with "right" edges from the 1st child to the 2nd child, 2nd child to third child, etc. Thus at each step one can either go down (append a (,1) to the end) or go right (add 1 to the last number) (except the root, which is extra and can only go down), which shows the correspondence between the infinite binary tree and the above numbering; the sum of the entries (minus 1) corresponds to the distance from the root, which agrees with the 2n 1 nodes at depth n1 in the infinite binary tree (2 corresponds to binary).

Implementations
p r e o r d e r ( n o d e ) i fn o d e= =n u l lt h e nr e t u r n p r i n tn o d e . v a l u e p r e o r d e r ( n o d e . l e f t ) p r e o r d e r ( n o d e . r i g h t )

i n o r d e r ( n o d e ) i fn o d e= =n u l lt h e nr e t u r n i n o r d e r ( n o d e . l e f t ) p r i n tn o d e . v a l u e i n o r d e r ( n o d e . r i g h t )

p o s t o r d e r ( n o d e ) i fn o d e= =n u l lt h e nr e t u r n p o s t o r d e r ( n o d e . l e f t ) p o s t o r d e r ( n o d e . r i g h t ) p r i n tn o d e . v a l u e

All sample implementations will require call stack space proportional to the height of the tree. In a poorly balanced tree, this can be quite considerable. We can remove the stack requirement by maintaining parent pointers in each node, or by threading the tree. To traverse inorder (in-order) without recursion a tree, whose nodes contain parent pointers
en.wikipedia.org/wiki/Tree_traversal 5/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

t y p e d e fs t r u c tt N o d e { s t r u c tt N o d e *c h i l d [ 2 ] ;/ /N U L L sf o rl e a v e s s t r u c tt N o d e *p a r e n t ;/ /N U L Lf o rr o o t i n td a t a ; }t N o d e ; t N o d e*f i r s t I n O r d e r N o d e( t N o d e *r o o t ) { i f( r o o t= =N U L L ){ / /t r e ei se m p t y r e t u r nN U L L ; } / /r e t u r nl e f t m o s tn o d ea sf i r s t t N o d e* n=r o o t ; w h i l e( n > c h i l d [ 0 ]! =N U L L ){ n=n > c h i l d [ 0 ] ; } r e t u r nn ; } t N o d e*n e x t I n O r d e r N o d e( t N o d e* n ) { i f( n > c h i l d [ 1 ]! =N U L L ){ / /w eh a v ear i g h ts u b t r e e-n e x tn o d ei sl e f t m o s tn o d ei nt h er i g h ts u b t r e e n=n > c h i l d [ 1 ] ; w h i l e( n > c h i l d [ 0 ]! =N U L L ){ n=n > c h i l d [ 0 ] ; } }e l s e{ / /w ed on o th a v ear i g h ts u b t r e e-n e x tn o d ei st h ef i r s tn o d eu p w a r d st h a t / /d o e sn o tc o n t a i nt h i sn o d ei ni t sr i g h ts u b t r e e( i ft h e r ei sn os u c hn o d e , / /t h i si st h el a s t( r i g h t m o s t )n o d e ,a n dw er e t u r nN U L L ) . w h i l e( n > p a r e n t! =N U L L& &n= =n > p a r e n t > c h i l d [ 1 ] ){ n=n > p a r e n t ; } n=n > p a r e n t ; } r e t u r nn ; } v o i dn o n R e c u r s i v e I n O r d e r T r a v e r s a l( t N o d e *r o o t ) { f o r( t N o d e* n=f i r s t I n O r d e r N o d e ( r o o t ) ;n! =N U L L ;n=n e x t I n O r d e r N o d e ( n ) ){ p r i n t f ( " w ea r ea t% d \ n " ,n > d a t a ) ; } }

The time complexity of a single iteration step using the above algorithm is limited by the height of the tree, which is O(log n) for balanced trees. However, since each edge is traversed exactly twice (once when entering a subtree and once when leaving it), the amortized traversal time is O(n). In the case of using threads, this will allow for greatly improved inorder traversal, although retrieving the parent node required for preorder and postorder traversal will be slower than a simple stack based algorithm. To traverse a threaded tree inorder, we could do something like this:
i n o r d e r ( n o d e ) w h i l eh a s l e f t c h i l d ( n o d e )d o n o d e=n o d e . l e f t d o v i s i t ( n o d e ) i f( h a s r i g h t c h i l d ( n o d e ) )t h e n n o d e=n o d e . r i g h t w h i l eh a s l e f t c h i l d ( n o d e )d o n o d e=n o d e . l e f t e l s e
en.wikipedia.org/wiki/Tree_traversal 6/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

w h i l en o d e . p a r e n tn u l la n dn o d e= =n o d e . p a r e n t . r i g h td o n o d e=n o d e . p a r e n t n o d e=n o d e . p a r e n t w h i l en o d en u l l

Note that a threaded binary tree will provide a means of determining whether a pointer is a child, or a thread. See threaded binary trees for more information. To traverse a threaded tree inorder (in-order) without recursion
v o i dI n O r d e r T r a v e r s a l ( s t r u c tN o d e* n ) { s t r u c tN o d e* C u r ,* P r e ; i f ( n = = N U L L ) r e t u r n ; C u r=n ; w h i l e ( C u r! =N U L L ) { i f ( C u r > l p t r= =N U L L ) { p r i n t f ( " \ t % d " , C u r > v a l ) ; C u r =C u r > r p t r ; } e l s e { P r e=C u r > l p t r ; w h i l e ( P r e > r p t r! = N U L L& &P r e > r p t r! =C u r ) P r e=P r e > r p t r ; i f( P r e > r p t r= =N U L L ) { P r e > r p t r=C u r ; C u r=C u r > l p t r ; } e l s e { P r e > r p t r=N U L L ; p r i n t f ( " \ t % d " , C u r > v a l ) ; C u r=C u r > r p t r ; }

Queue-based level order traversal


Also, listed below is pseudocode for a simple queue based level order traversal, and will require space proportional to the maximum number of nodes at a given depth. This can be as much as the total number of nodes / 2. A more space-efficient approach for this type of traversal can be implemented using an iterative deepening depth-first search.
l e v e l o r d e r ( r o o t ) q=e m p t yq u e u e q . e n q u e u e ( r o o t ) w h i l en o tq . e m p t yd o n o d e: =q . d e q u e u e ( ) v i s i t ( n o d e ) i fn o d e . l e f tn u l l q . e n q u e u e ( n o d e . l e f t ) i fn o d e . r i g h tn u l l q . e n q u e u e ( n o d e . r i g h t )
en.wikipedia.org/wiki/Tree_traversal 7/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

Uses
Inorder traversal It is particularly common to use an inorder traversal on a binary search tree because this will return values from the underlying set in order, according to the comparator that set up the binary search tree (hence the name). To see why this is the case, note that if n is a node in a binary search tree, then everything in n 's left subtree is less than n, and everything in n 's right subtree is greater than or equal to n. Thus, if we visit the left subtree in order, using a recursive call, and then visit n, and then visit the right subtree in order, we have visited the entire subtree rooted at n in order. We can assume the recursive calls correctly visit the subtrees in order using the mathematical principle of structural induction. Traversing in reverse inorder similarly gives the values in decreasing order. Preorder traversal Traversing a tree in preorder while inserting the values into a new tree is common way of making a complete copy of a binary search tree. One can also use preorder traversals to get a prefix expression (Polish notation) from expression trees: traverse the expression tree preorderly. To calculate the value of such an expression: scan from right to left, placing the elements in a stack. Each time we find an operator, we replace the two top symbols of the stack with the result of applying the operator to those elements. For instance, the expression + 2 3 4, which in infix notation is (2 + 3) 4, would be evaluated like this: Using prefix traversal to evaluate an expression tree Expression (remaining) +234 +23 +2 + Answer Stack <empty> 4 34 234 54 20

Functional traversal
We could perform the same traversals in a functional language like Haskell using code similar to the below. Functional breadth-first traversal is one motivation for corecursion.
d a t aT r e ea=N i l|N o d e( T r e ea )a( T r e ea ) p r e o r d e rN i l=[ ] p r e o r d e r( N o d el e f txr i g h t )=[ x ]+ +( p r e o r d e rl e f t )+ +( p r e o r d e rr i g h t )
en.wikipedia.org/wiki/Tree_traversal 8/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

p o s t o r d e rN i l=[ ] p o s t o r d e r( N o d el e f txr i g h t )=( p o s t o r d e rl e f t )+ +( p o s t o r d e rr i g h t )+ +[ x ] i n o r d e rN i l=[ ] i n o r d e r( N o d el e f txr i g h t )=( i n o r d e rl e f t )+ +[ x ]+ +( i n o r d e rr i g h t ) l e v e l o r d e rt=s t e p[ t ] w h e r e s t e p[ ]=[ ] s t e pt s=c o n c a t M a pe l e m e n t st s+ +s t e p( c o n c a t M a ps u b t r e e st s ) e l e m e n t sN i l=[ ] e l e m e n t s( N o d el e f txr i g h t )=[ x ] s u b t r e e sN i l=[ ] s u b t r e e s( N o d el e f txr i g h t )=[ l e f t ,r i g h t ]

Iterative Traversal
All the above recursive algorithms require stack space proportional to the depth of the tree. Recursive traversal may be converted into an iterative one using various well-known methods. A sample is shown here for postorder traversal using a visited flag:
i t e r a t i v e P o s t o r d e r ( r o o t N o d e ) n o d e S t a c k . p u s h ( r o o t N o d e ) w h i l e( !n o d e S t a c k . e m p t y ( ) ) c u r r N o d e=n o d e S t a c k . p e e k ( ) i f( ( c u r r N o d e . l e f t! =n u l l )a n d( c u r r N o d e . l e f t . v i s i t e d= =f a l s e ) ) n o d e S t a c k . p u s h ( c u r r N o d e . l e f t ) e l s e i f( ( c u r r N o d e . r i g h t! =n u l l )a n d( c u r r N o d e . r i g h t . v i s i t e d= =f a l s e ) ) n o d e S t a c k . p u s h ( c u r r N o d e . r i g h t ) e l s e p r i n tc u r r N o d e . v a l u e c u r r N o d e . v i s i t e d: =t r u e n o d e S t a c k . p o p ( )

In this case each node is required to keep an additional "visited" flag, other than usual information (value, left-childreference, right-child-reference). Another sample is shown here for postorder traversal without requiring any additional bookkeeping flags (C++):
v o i di t e r a t i v e P o s t O r d e r ( N o d e *r o o t ){ i f( ! r o o t ){ r e t u r n ; } s t a c k < N o d e * >n o d e S t a c k ; N o d e *c u r=r o o t ; w h i l e( t r u e ){ i f( c u r ){ i f( c u r > r i g h t ){ n o d e S t a c k . p u s h ( c u r > r i g h t ) ; } n o d e S t a c k . p u s h ( c u r ) ; c u r=c u r > l e f t ; c o n t i n u e ; } i f( n o d e S t a c k . e m p t y ( ) ){ r e t u r n ; } c u r=n o d e S t a c k . t o p ( ) ;
en.wikipedia.org/wiki/Tree_traversal 9/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

n o d e S t a c k . p o p ( ) ; i f( c u r > r i g h t& &! n o d e S t a c k . e m p t y ( )& &c u r > r i g h t= =n o d e S t a c k . t o p ( ) ){ n o d e S t a c k . p o p ( ) ; n o d e S t a c k . p u s h ( c u r ) ; c u r=c u r > r i g h t ; }e l s e{ s t d : : c o u t< <c u r > v a l< <"" ; c u r=N U L L ; }

Another example is preorder traversal without using a visited flag (Java):


p u b l i cv o i di t e r a t i v e P r e o r d e r ( N o d er o o t ){ S t a c kn o d e s=n e wS t a c k ( ) ; n o d e s . p u s h ( r o o t ) ; N o d ec u r r e n t N o d e ; w h i l e( ! n o d e s . i s E m p t y ( ) ){ c u r r e n t N o d e=n o d e s . p o p ( ) ; N o d er i g h t=c u r r e n t N o d e . r i g h t ( ) ; i f( r i g h t! =n u l l ){ n o d e s . p u s h ( r i g h t ) ; } N o d el e f t=c u r r e n t N o d e . l e f t ( ) ; i f( l e f t! =n u l l ){ n o d e s . p u s h ( l e f t ) ; } S y s t e m . o u t . p r i n t l n ( " N o d ed a t a :" + c u r r e n t N o d e . d a t a ) ; }

If each node holds reference to the parent node, then iterative traversal is possible without a stack or "visited" flag. Here is another example of iterative inorder traversal in (C++):
v o i di t e r a t i v e I n o r d e r ( N o d e *r o o t ){ s t a c k < N o d e * >n o d e S t a c k ; N o d e* c u r r=r o o t ; w h i l e( t r u e ){ i f( c u r r ){ n o d e S t a c k . p u s h ( c u r r ) ; c u r r=c u r r > l e f t ; c o n t i n u e ; } i f( ! n o d e S t a c k . s i z e ( ) ){ r e t u r n ; } c u r r=n o d e S t a c k . t o p ( ) ; n o d e S t a c k . p o p ( ) ; s t d : : c o u t< <" N o d ed a t a :"< <c u r r > d a t a< <s t d : : e n d l ; c u r r=c u r r > r i g h t ; } }

Iterative inorder traversal in (Java):


p u b l i cv o i dt r a v e r s e T r e e I n O r d e r ( N o d en o d e ){ / / i n c o m i n gn o d ei sr o o t S t a c k < N o d e >n o d e s=n e wS t a c k < N o d e > ( ) ; w h i l e( ! n o d e s . i s E m p t y ( )| |n u l l! =n o d e ){ i f( n u l l! =n o d e ){ n o d e s . p u s h ( n o d e ) ;
en.wikipedia.org/wiki/Tree_traversal 10/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

n o d e=n o d e . l e f t ; }e l s e{ n o d e=n o d e s . p o p ( ) ; S y s t e m . o u t . p r i n t l n ( " N o d ev a l u e :"+n o d e . v a l u e ) ; n o d e=n o d e . r i g h t ; }

Recursive Traversals in C
Recursive algorithms can be written for tree traversals. The data structure of the tree can be written as:[3]
t y p e d e fs t r u c tn o d e { i n tv a l ; s t r u c tn o d e* l e f t ,* r i g h t ; } * t r e e ;/ / t r e eh a sb e e nt y p e d e f e da san o d ep o i n t e r .

For the above data structure, the basic tree traversals can be written as shown below: Inorder Traversal
v o i di n o r d e r ( t r e et ) { i f ( t= =N U L L ) r e t u r n ; i n o r d e r ( t > l e f t ) ; p r i n t f ( " % d" ,t > v a l ) ; i n o r d e r ( t > r i g h t ) ; }

Preorder Traversal
v o i dp r e o r d e r ( t r e et ) { i f ( t= =N U L L ) r e t u r n ; p r i n t f ( " % d" ,t > v a l ) ; p r e o r d e r ( t > l e f t ) ; p r e o r d e r ( t > r i g h t ) ; }

Postorder Traversal
v o i dp o s t o r d e r ( t r e et ) { i f ( t= =N U L L ) r e t u r n ; p o s t o r d e r ( t > l e f t ) ; p o s t o r d e r ( t > r i g h t ) ; p r i n t f ( " % d" ,t > v a l ) ; }

References
en.wikipedia.org/wiki/Tree_traversal 11/12

08/08/12

Tree traversal - Wikipedia, the free encyclopedia

1. ^ a b c http://webdocs.cs.ualberta.ca/~holte/T26/tree-traversal.html 2. ^ Which combinations of pre-, post- and in-order sequentialisation are unique? (http://cs.stackexchange.com/questions/439/which-combinations-of-pre-post-and-in-order-sequentialisation-areunique) 3. ^ "Tree->Traversal" (http://datastructures.itgo.com/trees/traversal.htm) . Datastructures.itgo.com. http://datastructures.itgo.com/trees/traversal.htm. Retrieved 2012-02-24.

Dale, Nell. Lilly, Susan D. "Pascal Plus Data Structures". D. C. Heath and Company. Lexington, MA. 1995. Fourth Edition. Drozdek, Adam. "Data Structures and Algorithms in C++". Brook/Cole. Pacific Grove, CA. 2001. Second edition. http://www.math.northwestern.edu/~mlerma/courses/cs310-05s/notes/dm-treetran

External links
Animation Applet of Binary Tree Traversal (http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/BTree.html) The Adjacency List Model for Processing Trees with SQL (http://www.SQLSummit.com/AdjacencyList.htm) Storing Hierarchical Data in a Database (http://www.sitepoint.com/article/hierarchical-data-database) with traversal examples in PHP Managing Hierarchical Data in MySQL (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html) Working with Graphs in MySQL (http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html) Non-recursive traversal of DOM trees in JavaScript (http://www.jslab.dk/articles/non.recursive.preorder.traversal) Sample code for recursive and iterative tree traversal implemented in C. (http://code.google.com/p/treetraversal/) Sample code for recursive tree traversal in C#. (http://arachnode.net/blogs/programming_challenges/archive/2009/09/25/recursive-tree-traversalorders.aspx) See tree traversal implemented in various programming language (http://rosettacode.org/wiki/Tree_traversal) on Rosetta Code Tree traversal without recursion (http://www.perlmonks.org/?node_id=600456) Retrieved from "http://en.wikipedia.org/w/index.php?title=Tree_traversal&oldid=506454666" Categories: Trees (data structures) Articles with example Haskell code Articles with example Java code Graph algorithms This page was last modified on 8 August 2012 at 21:28. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. See Terms of use for details. Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.

en.wikipedia.org/wiki/Tree_traversal

12/12

You might also like