Non Recursive Algorithm to Traverse a Binary Tree, Data Structure & Algorithms

Q. Write down a non recursive algorithm to traverse a binary tree in order.                   

Ans:

Non - recursive algorithm to traverse a binary tree in inorder is as follows:-

Initially in the beginning   push NULL  onto STACK  and then set  PTR  = ROOT. Then    repeat the steps written below until   NULL is popped from STACK.

i.      Continue down the left -most path rooted at PTR, pushing each node N onto STACK and stopping when a node     N    with no left    child     is   pushed    onto

STACK.

ii.    [Backtracking.] Pop and  process the nodes on

STACK. If the NULL is popped then Exit. If a node N

Having a right child R(N) is processed, set PTR = R(N) (by assigning PTR = RIGHT[PTR] and return to the Step(a)).

 

 

Posted Date: 7/10/2012 5:56:43 AM | Location : United States







Related Discussions:- Non Recursive Algorithm to Traverse a Binary Tree, Assignment Help, Ask Question on Non Recursive Algorithm to Traverse a Binary Tree, Get Answer, Expert's Help, Non Recursive Algorithm to Traverse a Binary Tree Discussions

Write discussion on Non Recursive Algorithm to Traverse a Binary Tree
Your posts are moderated
Related Questions
It is a naturally occurring sorting method exemplified through a card player arranging the cards dealt to him. He picks up the cards like they are dealt & added them into the neede

An undirected graph G with n vertices and e edges is shown by adjacency list.  What is the time required to generate all the connected components? O (e+n)

This is a unit of which targeted on the emerging data structures. Red- Black trees, Splay trees, AA-trees & Treaps are introduced. The learner must explore the possibilities of app

In file access: what is the difference between serial, sequential and indexed sequential searching

how to convert 12 hour format into 24 hour format using c program

Typical programming languages such as Pascal, C or Java give primitive data kinds such as integers, boolean, reals values and strings. They give these to be organised into arrays,

Write the algorithm for Binary search. Also apply this algorithm on the following data. 22, 44, 11, 88, 33, 55, 77, 66

Q. Write down an algorithm to insert a node in the beginning of the linked list.                         Ans: /* structure containing a link part and link part

difference between recursion and iteration

how we can convert a graph into tree